Skip to content
Myr

Added expiration support to cache api with reaper. Closes #133

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

authored by visionmedia · committed by visionmedia · parent 200d09c · Browse files · 3 files+35 added−5 removed
This commit

State

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

Diff stats

3 files+35 added−5 removed

  • other:+35 added−5 removed

3 files+35 added−5 removed

modified:lib/express/plugins/cache.js+32 added-5 removed
173 unmodified lines
174 return new RegExp('^' + pattern.replace(/[*]/g, '(.*?)') + '$')175 }176})177178// --- Cache179180exports.Cache = Plugin.extend({181 extend: {182 183 /**182 * Initialize extensions.184 * Initialize memory store and start reaper.185 *186 * Options:187 *188 * - dataStore constructor name of cache data store, defaults to Store.Memory189 * - lifetime lifetime of cache in milliseconds, defaults to one day190 * - reapInterval interval in milliseconds in which to reap old caches, defaults to one hour191 * 192 * @param {hash} options193 * @api private194 */195 185 init: function() {186 Request.include({187 cache: new exports.Store.Memory188 })196 init: function(options) {197 process.mixin(this, options)198 this.store = new (this.dataStore || exports.Store.Memory)(options)199 Request.include({ cache: this.store })200 this.startReaper()201 },202 203 /**204 * Start reaper.205 *206 * @api private207 */208 209 startReaper: function() {210 var self = this,211 oneDay = 86400000,212 oneHour = 3600000213 setInterval(function(){214 self.store.reap(self.lifetime || oneDay)215 }, self.reapInterval || oneHour)216 }217 }218})
modified:lib/express/plugins/session.js+2 added
136 unmodified lines
137 })138 }139})140141// --- Cache142143exports.Session = Plugin.extend({144 extend: {145 146 /**
59 unmodified lines
modified:lib/express/plugins.js+1 added