|
|
@ -53,6 +53,8 @@ var multiCaching = function(caches, options) { |
|
|
|
options = {}; |
|
|
|
} |
|
|
|
|
|
|
|
var defer = Promise.defer(); |
|
|
|
|
|
|
|
var i = 0; |
|
|
|
async.eachSeries(caches, function(cache, next) { |
|
|
|
var callback = function(err, result) { |
|
|
@ -66,9 +68,8 @@ var multiCaching = function(caches, options) { |
|
|
|
// break out of async loop.
|
|
|
|
if (typeof cb === 'function') { |
|
|
|
return cb(err, result, i); |
|
|
|
} else { |
|
|
|
return cb.resolve(result); |
|
|
|
} |
|
|
|
return defer.resolve(result); |
|
|
|
} |
|
|
|
|
|
|
|
i += 1; |
|
|
@ -77,16 +78,17 @@ var multiCaching = function(caches, options) { |
|
|
|
|
|
|
|
cache.store.get(key, options, callback); |
|
|
|
}, function(err, result) { |
|
|
|
if (typeof cb === 'object') { |
|
|
|
if (err) { |
|
|
|
cb.reject(err); |
|
|
|
} else { |
|
|
|
cb.resolve(result); |
|
|
|
} |
|
|
|
} else if (typeof cb === 'function') { |
|
|
|
if (typeof cb === 'function') { |
|
|
|
cb(err, result); |
|
|
|
} |
|
|
|
|
|
|
|
if (err) { |
|
|
|
return defer.reject(err); |
|
|
|
} |
|
|
|
defer.resolve(result); |
|
|
|
}); |
|
|
|
|
|
|
|
return defer.promise; |
|
|
|
} |
|
|
|
|
|
|
|
function setInMultipleCaches(caches, opts, cb) { |
|
|
@ -120,19 +122,15 @@ var multiCaching = function(caches, options) { |
|
|
|
* @param {function} cb |
|
|
|
*/ |
|
|
|
self.getAndPassUp = function(key, cb) { |
|
|
|
getFromHighestPriorityCache(key, function(err, result, index) { |
|
|
|
return getFromHighestPriorityCache(key, function(err, result, index) { |
|
|
|
if (err) { |
|
|
|
if (typeof cb === 'function') { |
|
|
|
if (cb) { |
|
|
|
return cb(err); |
|
|
|
} else { |
|
|
|
return cb.reject(err); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof cb === 'function') { |
|
|
|
if (cb) { |
|
|
|
cb(err, result); |
|
|
|
} else { |
|
|
|
cb.resolve(result); |
|
|
|
} |
|
|
|
|
|
|
|
if (index) { |
|
|
@ -282,11 +280,7 @@ var multiCaching = function(caches, options) { |
|
|
|
options = {}; |
|
|
|
} |
|
|
|
|
|
|
|
var defer = Promise.defer(); |
|
|
|
|
|
|
|
getFromHighestPriorityCache(key, options, cb || defer); |
|
|
|
|
|
|
|
return defer.promise; |
|
|
|
return getFromHighestPriorityCache(key, options, cb); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|