Skip to content
Myr

fn -> callback

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

authored by visionmedia · committed by visionmedia · parent c09e546 · Browse files · 1 file+14 added−12 removed
This commit

State

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

Diff stats

1 file+14 added−12 removed

  • other:+14 added−12 removed

1 file+14 added−12 removed

modified:lib/express/plugins/cache.js+14 added-12 removed
82 unmodified lines
83 * Set the given _key_ to _val_.84 *85 * @param {string} key86 * @param {string} val87 * @param {function} fn87 * @param {function} callback88 * @return {string}89 * @api public90 */91 92 set: function(key, val, fn) {92 set: function(key, val, callback) {93 exports.Store.prototype.set.apply(this, arguments)94 this.data[key] = new Cache(key, val)95 if (fn instanceof Function) fn(val)95 if (callback) callback(val)96 },97 98 /**99 * Get data found matching the given _key_.
8 unmodified lines
108 * 'page:users': '<html>...</html>',109 * ... }110 *111 * @param {string} key112 * @param {function} fn112 * @param {function} callback113 * @return {mixed}114 * @api public115 */116 117 get: function(key, fn) {117 get: function(key, callback) {118 exports.Store.prototype.get.apply(this, arguments)119 if (key.indexOf('*') === -1)120 return fn(this.data[key] instanceof Cache120 return callback(this.data[key] instanceof Cache121 ? this.data[key].val122 : null)123 var regexp = this.normalize(key) 124 fn(this.data.reduce(function(vals, cache){124 callback(this.data.reduce(function(vals, cache){125 if (regexp.test(cache.key))126 vals[cache.key] = cache.val127 return vals128 }, {}))
7 unmodified lines
136 * cache.clear('page:front', function(){})137 * cache.clear('page:*', function(){})138 *139 * @param {string} key140 * @param {function} fn140 * @param {function} callback141 * @api public142 */143 144 clear: function(key, fn) {144 clear: function(key, callback) {145 if (key.indexOf('*') === -1)146 delete this.data[key]147 else {148 var regexp = this.normalize(key)
1 unmodified line
150 if (this.data.hasOwnProperty(key))151 if (regexp.test(key))152 delete this.data[key]153 }154 fn()154 callback()155 },156 157 /**158 * Reap caches older than _ms_.
1 unmodified line
160 * @param {int} ms161 * @api private162 */163 164 reap: function(ms) {164 reap: function(ms, callback) {165 var self = this,166 threshold = Number(new Date(Number(new Date) - ms))167 this.data.each(function(cache){168 if (cache.created < threshold)169 self.clear(cache.key, function(){})170 })171 if (callback) callback()172 },173 174 /**175 * Convert the given key matching _pattern_
38 unmodified lines
214 215 /**216 * Start reaper.217 *218 * @param {function} callback219 * @api private220 */221 220 startReaper: function() {222 startReaper: function(callbac) {223 setInterval(function(self){224 self.store.reap(self.lifetime || (1).day)225 }, this.reapInterval || this.reapEvery || (1).hour, this)226 }
2 unmodified lines