|
@ -64,7 +64,11 @@ var multiCaching = function(caches, options) { |
|
|
|
|
|
|
|
|
if (_isCacheableValue(result)) { |
|
|
if (_isCacheableValue(result)) { |
|
|
// break out of async loop.
|
|
|
// break out of async loop.
|
|
|
return cb(err, result, i); |
|
|
if (typeof cb === 'function') { |
|
|
|
|
|
return cb(err, result, i); |
|
|
|
|
|
} else { |
|
|
|
|
|
return cb.resolve(result); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
i += 1; |
|
|
i += 1; |
|
@ -72,7 +76,17 @@ var multiCaching = function(caches, options) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
cache.store.get(key, options, callback); |
|
|
cache.store.get(key, options, callback); |
|
|
}, cb); |
|
|
}, function(err, result) { |
|
|
|
|
|
if (typeof cb === 'object') { |
|
|
|
|
|
if (err) { |
|
|
|
|
|
cb.reject(err); |
|
|
|
|
|
} else { |
|
|
|
|
|
cb.resolve(result); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (typeof cb === 'function') { |
|
|
|
|
|
cb(err, result); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function setInMultipleCaches(caches, opts, cb) { |
|
|
function setInMultipleCaches(caches, opts, cb) { |
|
@ -85,7 +99,17 @@ var multiCaching = function(caches, options) { |
|
|
} else { |
|
|
} else { |
|
|
next(); |
|
|
next(); |
|
|
} |
|
|
} |
|
|
}, cb); |
|
|
}, function(err, result) { |
|
|
|
|
|
if (typeof cb === 'object') { |
|
|
|
|
|
if (err) { |
|
|
|
|
|
cb.reject(err); |
|
|
|
|
|
} else { |
|
|
|
|
|
cb.resolve(result); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (typeof cb === 'function') { |
|
|
|
|
|
cb(err, result); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -98,10 +122,18 @@ var multiCaching = function(caches, options) { |
|
|
self.getAndPassUp = function(key, cb) { |
|
|
self.getAndPassUp = function(key, cb) { |
|
|
getFromHighestPriorityCache(key, function(err, result, index) { |
|
|
getFromHighestPriorityCache(key, function(err, result, index) { |
|
|
if (err) { |
|
|
if (err) { |
|
|
return cb(err); |
|
|
if (typeof cb === 'function') { |
|
|
|
|
|
return cb(err); |
|
|
|
|
|
} else { |
|
|
|
|
|
return cb.reject(err); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cb(err, result); |
|
|
if (typeof cb === 'function') { |
|
|
|
|
|
cb(err, result); |
|
|
|
|
|
} else { |
|
|
|
|
|
cb.resolve(result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (index) { |
|
|
if (index) { |
|
|
var cachesToUpdate = caches.slice(0, index); |
|
|
var cachesToUpdate = caches.slice(0, index); |
|
@ -227,7 +259,11 @@ var multiCaching = function(caches, options) { |
|
|
options: options |
|
|
options: options |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
setInMultipleCaches(caches, opts, cb); |
|
|
var defer = Promise.defer(); |
|
|
|
|
|
|
|
|
|
|
|
setInMultipleCaches(caches, opts, cb || defer); |
|
|
|
|
|
|
|
|
|
|
|
return defer.promise; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -246,7 +282,11 @@ var multiCaching = function(caches, options) { |
|
|
options = {}; |
|
|
options = {}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getFromHighestPriorityCache(key, options, cb); |
|
|
var defer = Promise.defer(); |
|
|
|
|
|
|
|
|
|
|
|
getFromHighestPriorityCache(key, options, cb || defer); |
|
|
|
|
|
|
|
|
|
|
|
return defer.promise; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|