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 fileTake it
Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
lines 1–21why, one step back12describe '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 back22 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 back30 endMerge branch 'cache-lifetime'visionmediabefore adoption5ce1306
lines 31–37why, one step back31 end32 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 back38 end39 Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306
lines 40–43why, one step back40 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 back44 end45 Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306
lines 46–47why, one step back46 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 back48 end49 end50 Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306
lines 51–53why, one step back51 describe 'given an abitrary key'52 it 'should throw an error'53 -{ store.set({}, 'foo') }.should.throw_errorMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
line 54why, one step back54 endMerge branch 'cache-lifetime'visionmediabefore adoption5ce1306
lines 55–69why, one step back55 end56 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 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
line 70why, one step back70 Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306
lines 71–73why, one step back71 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 back74 end75 end76 Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306
lines 77–82why, one step back77 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 back83 endMerge branch 'cache-lifetime'visionmediabefore adoption5ce1306
lines 84–92why, one step back84 end85 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_nullMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
lines 93–95why, one step back93 end94 end95 Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306
lines 96–116why, one step back96 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 endMerge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption704c933
lines 117–119why, one step back117 end118 end119end