mirror of
https://github.com/BreizhHardware/memoizee.git
synced 2026-03-18 21:40:27 +01:00
async: safe purgeAll
This commit is contained in:
@@ -10,7 +10,7 @@ var toArray = require('es5-ext/lib/Array/from')
|
||||
, apply = Function.prototype.apply;
|
||||
|
||||
require('../_base').ext.async = function (ignore, conf, options) {
|
||||
var cache;
|
||||
var cache, purge;
|
||||
|
||||
cache = conf.async = {};
|
||||
|
||||
@@ -97,16 +97,17 @@ require('../_base').ext.async = function (ignore, conf, options) {
|
||||
|
||||
}(conf.fn));
|
||||
|
||||
conf.on('purge', function (id) {
|
||||
conf.on('purge', purge = function (id) {
|
||||
// If false, we don't have value yet, so we assume that intention is not
|
||||
// to memoize this call. After value is obtained we don't cache it but
|
||||
// gracefully pass to callback
|
||||
if (!isArray(cache[id])) {
|
||||
conf.emit('purgeasync', id);
|
||||
delete cache[id];
|
||||
}
|
||||
});
|
||||
|
||||
conf.on('purgeall', function () {
|
||||
cache = conf.async = {};
|
||||
forEach(conf.async, function (value, id) { purge(id); });
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user