Skip to content
Myr

Finished converting async cache api. Closes #240

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent b85cda3 · Browse files · 9 files+53 added−109 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+53 added−109 removed

  • tests:+12 added−4 removed
  • other:+41 added−105 removed

9 files+53 added−109 removed

modified:lib/express/plugins/cache.js+3 added-2 removed
78 unmodified lines
79 this.data = {}80 },81 82 /**83 * Set the given _key_ to _val_, passing _val_.83 * Set the given _key_ to _val_.84 *85 * @param {string} key86 * @param {string} val87 * @param {function} fn
2 unmodified lines
90 */91 92 set: function(key, val, fn) {93 exports.Store.prototype.set.apply(this, arguments)94 return this.data[key] = new Cache(key, val), fn(val)94 this.data[key] = new Cache(key, val)95 if (fn instanceof Function) fn(val)96 },97 98 /**99 * Get data found matching the given _key_.
127 unmodified lines
modified:lib/express/plugins/static.js+24 added-15 removed
modified:lib/express/plugins/view.js+13 added-6 removed
59 unmodified lines
60 * @api public61 */6263 render: function(view, options) {64 var cache,65 self = this,64 var self = this,65 options = options || {},66 path = set('views') + '/' + view,67 type = path.split('.').slice(-2)[0],68 ext = extname(path),
11 unmodified lines
80 }))81 else82 self.halt(200, content)83 }85 if (set('cache view contents') && (cache = self.cache.get('view:' + path)))86 render(cache)87 else84 function renderFromDisc() {85 fs.readFile(path, function(err, content){86 if (err) throw err87 set('cache view contents')91 ? render(self.cache.set('view:' + path, content))88 ? self.cache.set('view:' + path, content, function(cache){89 render(cache)90 })91 : render(content)92 })93 }94 if (set('cache view contents'))95 self.cache.get('view:' + path, function(cache){96 if (cache) render(cache)97 else renderFromDisc()98 })99 else100 renderFromDisc()101 }102 })103 }104 }
2 unmodified lines
modified:lib/express/request.js+1 added-18 removed
3 unmodified lines
4/**5 * Module dependencies.6 */78var StaticFile = require('express/static').File,9 statusBodies = require('http').STATUS_CODES,8var statusBodies = require('http').STATUS_CODES,9 queryString = require('querystring'),10 mime = require('express/mime'),11 utils = require('express/utils'),12 url = require('url')
266 unmodified lines
279 this.header('content-disposition', path280 ? 'attachment; filename="' + path + '"'281 : 'attachment')282 return this284 },285 286 /**287 * Transfer static file at the given _path_.288 *289 * @param {string} path290 * @return {Request}291 * @api public292 */293 294 // DEPRECATED: remove in 0.9.0295 296 sendfile: function(path) {297 Ext.warn('Request#sendfile() is deprecated, it is now part of the Static plugin, use(Static) to re-gain this method')298 (new StaticFile(path)).send(this)299 return this283 }284})
deleted:lib/express/static.js-64 removed
modified:spec/lib/jspec.js+2 added
1519 unmodified lines
1520 * @api public1521 */15221523 error : function(message, e) {1524 if ('stack' in e)1525 require('sys').puts(e.stack + '\n')1526 throw (message ? message : '') + e.toString() + 1527 (e.line ? ' near line ' + e.line : '')1528 },1529
246 unmodified lines
modified:spec/spec.plugins.cache.js+2 added-2 removed
137 unmodified lines
138 end139 140 describe '#reap()'141 it 'should destroy caches older than the given age in milliseconds'142 store.set('user:one', '1', function(){})142 store.set('user:one', '1')143 store.data['user:one'].created = Number((5).minutes.ago)144 store.set('user:two', '2', function(){})144 store.set('user:two', '2')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_null
8 unmodified lines
modified:spec/spec.plugins.static.js+4 added-1 removed
49 unmodified lines
50 get('/public/*', function(file){51 this.sendfile('spec/fixtures/' + file)52 })53 get('/cached', function(){54 return this.cache.get('static:spec/fixtures/user.json') ? 'yes' : 'no'54 var self = this55 this.cache.get('static:spec/fixtures/user.json', function(val){56 self.halt(200, val ? 'yes' : 'no')57 })58 })59 get('/cached').body.should.eql 'no'60 get('/public/user.json').body.should.include '"name":'61 get('/cached').body.should.eql 'yes'
17 unmodified lines
modified:spec/spec.plugins.view.js+4 added-1 removed
78 unmodified lines
79 get('/', function(){80 this.render('hello.haml.html')81 })82 get('/cached', function(){83 return this.cache.get('view:spec/fixtures/hello.haml.html') ? 'yes' : 'no'83 var self = this84 this.cache.get('view:spec/fixtures/hello.haml.html', function(val){85 self.halt(200, val ? 'yes' : 'no')86 })87 })88 get('/cached').body.should.eql 'no'89 get('/')90 get('/cached').body.should.eql 'yes'
62 unmodified lines