Skip to content
Myr

spec.plugins.cache.js

This file

Path

spec/spec.plugins.cache.js

119 lines · 3.1 KiB · JavaScript

Last changed by

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

History of this file

Take it

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

lines 1–21why, one step back
1
2describe 'Express'3 before_each4 reset()5 use(require('express/plugins/cache').Cache)6 cache = require('express/plugins/cache')7 end8 9 describe 'Cache'10 describe 'Request'11 describe '#cache'12 it 'should use memory store by default'13 get('/item', function(){14 return this.cache.toString()15 })16 get('/item').body.should.eql '[Memory Store]'17 end18 end19 end20 end21

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 22–29why, one step back
22 describe 'cache Store.Memory'
23 before_each24 store = new cache.Store.Memory25 end26 27 describe '#toString()'28 it 'should return [Memory Store]'29 store.toString().should.eql '[Memory Store]'

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

line 30why, one step back
30 end

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 31–37why, one step back
31 end
32 33 describe '#set()'34 describe 'given a key and value'35 it 'should set the cache data'36 store.set('foo', 'bar')37 store.get('foo').should.eql 'bar'

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

lines 38–39why, one step back
38 end
39

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 40–43why, one step back
40 it 'should override existing data'
41 store.set('foo', 'bar')42 store.set('foo', 'baz')43 store.get('foo').should.eql 'baz'

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

lines 44–45why, one step back
44 end
45

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 46–47why, one step back
46 it 'should return data'
47 store.set('foo', 'bar').should.eql 'bar'

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

lines 48–50why, one step back
48 end
49 end50

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 51–53why, one step back
51 describe 'given an abitrary key'
52 it 'should throw an error'53 -{ store.set({}, 'foo') }.should.throw_error

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

line 54why, one step back
54 end

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 55–69why, one step back
55 end
56 57 describe 'given an abitrary value'58 it 'should serialize as JSON'59 store.set('user', { name: 'tj' }).should.eql { name: 'tj' }60 end61 end62 end63 64 describe '#get()'65 describe 'given a key'66 it 'should return cached value'67 store.set('foo', 'bar')68 store.get('foo').should.eql 'bar'69 end

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

line 70why, one step back
70

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 71–73why, one step back
71 it 'should unserialize JSON data'
72 store.set('user', { name: 'tj' })73 store.get('user').should.eql { name: 'tj' }

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

lines 74–76why, one step back
74 end
75 end76

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 77–82why, one step back
77 describe 'given wildcards'
78 it 'should return a set of caches'79 store.set('user:1', 'a')80 store.set('user:2', 'b')81 store.set('foo', 'bar')82 store.get('user:*').should.eql { 'user:1': 'a', 'user:2': 'b' }

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

line 83why, one step back
83 end

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 84–92why, one step back
84 end
85 end86 87 describe '#clear()'88 describe 'given a key'89 it 'should delete previous data'90 store.set('foo', 'bar')91 store.clear('foo')92 store.get('foo').should.be_null

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

lines 93–95why, one step back
93 end
94 end95

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 96–116why, one step back
96 describe 'given wildcards'
97 it 'should clear a set of caches'98 store.set('user:one', '1')99 store.set('user:two', '2')100 store.clear('user:*')101 store.get('user:one').should.be_null102 store.get('user:two').should.be_null103 end104 end105 end106 107 describe '#reap()'108 it 'should destroy caches older than the given age in milliseconds'109 store.set('user:one', '1')110 store.data['user:one'].created = Number(new Date) - 300111 store.set('user:two', '2')112 store.data['user:two'].created = Number(new Date) - 100113 store.reap(200)114 store.get('user:one').should.be_null115 store.get('user:two').should.not.be_null116 end

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933

lines 117–119why, one step back
117 end
118 end119end