spec.plugins.cache.js
This file
Path
spec/spec.plugins.cache.js
110 lines · 2.8 KiB · JavaScript
Last changed by
Memory cache now allows objects as valuesvisionmediabefore adoption8207e70
History of this fileTake it
Started caching apivisionmediabefore adoptionc161750
lines 1–4why, one step back12describe 'Express'3 before_each4 reset()Started Store.Memory specsvisionmediabefore adoptiona82b1b9
lines 5–6why, one step back5 use(require('express/plugins/cache').Cache)6 cache = require('express/plugins/cache')Started caching apivisionmediabefore adoptionc161750
lines 7–16why, one step back7 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]'Started Store.Memory specsvisionmediabefore adoptiona82b1b9
lines 17–23why, one step back17 end18 end19 end20 end21 22 describe 'Store'23 describe 'Memory'Added memory store specsvisionmediabefore adoptionf2d08aa
lines 24–27why, one step back24 before_each25 store = new cache.Store.Memory26 end27 Started Store.Memory specsvisionmediabefore adoptiona82b1b9
lines 28–29why, one step back28 describe '#toString()'29 it 'should return [Memory Store]'Added memory store specsvisionmediabefore adoptionf2d08aa
line 30why, one step back30 store.toString().should.eql '[Memory Store]'Started caching apivisionmediabefore adoptionc161750
lines 31–32why, one step back31 end32 endAdded memory store specsvisionmediabefore adoptionf2d08aa
lines 33–45why, one step back33 34 describe '#set()'35 describe 'given a key and value'36 it 'should set the cache data'37 store.set('foo', 'bar')38 store.get('foo').should.eql 'bar'39 end40 41 it 'should override existing data'42 store.set('foo', 'bar')43 store.set('foo', 'baz')44 store.get('foo').should.eql 'baz'45 endStarted implemented cache methodsvisionmediabefore adoptiond4d76cd
lines 46–48why, one step back46 47 it 'should return data'48 store.set('foo', 'bar').should.eql 'bar'Added memory store specsvisionmediabefore adoptionf2d08aa
lines 49–58why, one step back49 end50 end51 52 describe 'given an abitrary key'53 it 'should throw an error'54 -{ store.set({}, 'foo') }.should.throw_error55 end56 end57 58 describe 'given an abitrary value'Memory cache now allows objects as valuesvisionmediabefore adoption8207e70
lines 59–60why, one step back59 it 'should serialize as JSON'60 store.set('user', { name: 'tj' }).should.eql { name: 'tj' }Added memory store specsvisionmediabefore adoptionf2d08aa
lines 61–69why, one step back61 end62 end63 end64 65 describe '#get()'66 describe 'given a key'67 it 'should return cached value'68 store.set('foo', 'bar')69 store.get('foo').should.eql 'bar'Memory cache now allows objects as valuesvisionmediabefore adoption8207e70
lines 70–74why, one step back70 end71 72 it 'should unserialize JSON data'73 store.set('user', { name: 'tj' })74 store.get('user').should.eql { name: 'tj' }Added memory store specsvisionmediabefore adoptionf2d08aa
lines 75–107why, one step back75 end76 end77 78 describe 'given wildcards'79 it 'should return a set of caches'80 store.set('user:1', 'a')81 store.set('user:2', 'b')82 store.set('foo', 'bar')83 store.get('user:*').should.eql { 'user:1': 'a', 'user:2': 'b' }84 end85 end86 end87 88 describe '#clear()'89 describe 'given a key'90 it 'should delete previous data'91 store.set('foo', 'bar')92 store.clear('foo')93 store.get('foo').should.be_null94 end95 end96 97 describe 'given wildcards'98 it 'should clear a set of caches'99 store.set('user:one', '1')100 store.set('user:two', '2')101 store.clear('user:*')102 store.get('user:one').should.be_null103 store.get('user:two').should.be_null104 end105 end106 end107 Started caching apivisionmediabefore adoptionc161750
lines 108–110why, one step back108 end109 end110end