Skip to content
Myr

spec.plugins.cache.js

This file

Path

spec/spec.plugins.cache.js

156 lines · 4.0 KiB · JavaScript

Last changed by

Merge branch 'async-cache'visionmediabefore adoption7606f1b

History of this file

Take it

The walk stopped after 200 commits: lines older than 20cf8f8 point at it.

Session options in chat sample appvisionmediabefore adoption20cf8f8

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]'

Session options in chat sample appvisionmediabefore adoption20cf8f8

line 30why, one step back
30 end

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 31–35why, one step back
31 end
32 33 describe '#set()'34 describe 'given a key and value'35 it 'should set the cache data'

Merge branch 'async-cache'visionmediabefore adoption7606f1b

lines 36–42why, one step back
36 var result
37 store.set('foo', 'bar', function(){38 store.get('foo', function(val){39 result = val40 })41 })42 result.should.eql 'bar'

Session options in chat sample appvisionmediabefore adoption20cf8f8

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

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

line 45why, one step back
45 it 'should override existing data'

Merge branch 'async-cache'visionmediabefore adoption7606f1b

lines 46–54why, one step back
46 var result
47 store.set('foo', 'bar', function(){48 store.set('foo', 'baz', function(){49 store.get('foo', function(val){50 result = val51 })52 })53 })54 result.should.eql 'baz'

Session options in chat sample appvisionmediabefore adoption20cf8f8

lines 55–57why, one step back
55 end
56 end57

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

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

Session options in chat sample appvisionmediabefore adoption20cf8f8

line 61why, one step back
61 end

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 62–65why, one step back
62 end
63 64 describe 'given an abitrary value'65 it 'should serialize as JSON'

Merge branch 'async-cache'visionmediabefore adoption7606f1b

lines 66–70why, one step back
66 var result
67 store.set('user', { name: 'tj' }, function(val){68 result = val69 })70 result.should.eql { name: 'tj' }

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 71–77why, one step back
71 end
72 end73 end74 75 describe '#get()'76 describe 'given a key'77 it 'should unserialize JSON data'

Merge branch 'async-cache'visionmediabefore adoption7606f1b

lines 78–84why, one step back
78 var result
79 store.set('user', { name: 'tj' }, function(){80 store.get('user', function(val){81 result = val82 })83 })84 result.should.eql { name: 'tj' }

Session options in chat sample appvisionmediabefore adoption20cf8f8

lines 85–87why, one step back
85 end
86 end87

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

line 88why, one step back
88 describe 'given wildcards'

Merge branch 'async-cache'visionmediabefore adoption7606f1b

lines 89–100why, one step back
89 it 'should pass a set of caches'
90 var result91 store.set('user:1', 'a', function(){92 store.set('user:2', 'b', function(){93 store.set('foo', 'bar', function(){94 store.get('user:*', function(val){95 result = val96 })97 })98 })99 })100 result.should.eql { 'user:1': 'a', 'user:2': 'b' }

Session options in chat sample appvisionmediabefore adoption20cf8f8

line 101why, one step back
101 end

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 102–107why, one step back
102 end
103 end104 105 describe '#clear()'106 describe 'given a key'107 it 'should delete previous data'

Merge branch 'async-cache'visionmediabefore adoption7606f1b

lines 108–116why, one step back
108 var result
109 store.set('foo', 'bar', function(){110 store.clear('foo', function(){111 store.get('foo', function(val){112 result = val113 })114 })115 })116 result.should.be_null

Session options in chat sample appvisionmediabefore adoption20cf8f8

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

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 120–121why, one step back
120 describe 'given wildcards'
121 it 'should clear a set of caches'

Merge branch 'async-cache'visionmediabefore adoption7606f1b

lines 122–135why, one step back
122 var results = []
123 store.set('user:one', '1', function(){124 store.set('user:two', '2', function(){125 store.clear('user:*', function(){126 store.get('user:one', function(val){127 results.push(val)128 store.get('user:two', function(val){129 results.push(val)130 })131 })132 })133 }) 134 })135 results.should.eql [null, null]

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

lines 136–142why, one step back
136 end
137 end138 end139 140 describe '#reap()'141 it 'should destroy caches older than the given age in milliseconds'142 store.set('user:one', '1')

Merge branch 'async-cache'visionmediabefore adoption7606f1b

line 143why, one step back
143 store.data['user:one'].created = Number((5).minutes.ago)

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

line 144why, one step back
144 store.set('user:two', '2')

Merge branch 'async-cache'visionmediabefore adoption7606f1b

lines 145–152why, one step back
145 store.data['user:two'].created = Number((2).seconds.ago)
146 store.reap((1).minute)147 store.get('user:one', function(val){148 val.should.be_null149 })150 store.get('user:two', function(val){151 val.should.not.be_null152 })

Merge branch 'cache-lifetime'visionmediabefore adoption5ce1306

line 153why, one step back
153 end

Session options in chat sample appvisionmediabefore adoption20cf8f8

lines 154–156why, one step back
154 end
155 end156end