|
|
@ -91,20 +91,29 @@ define([
|
|
|
|
array.splice(0, firstCpIdx);
|
|
|
|
array.splice(0, firstCpIdx);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
S.storeCache = function (id, validateKey, val, cb) {
|
|
|
|
var t = {};
|
|
|
|
cb = Util.once(Util.mkAsync(cb || function () {}));
|
|
|
|
S.storeCache = function (id, validateKey, val, onError) {
|
|
|
|
|
|
|
|
onError = Util.once(Util.mkAsync(onError || function () {}));
|
|
|
|
|
|
|
|
|
|
|
|
onReady.reg(function () {
|
|
|
|
onReady.reg(function () {
|
|
|
|
if (!allowed) { return void cb('NOCACHE'); }
|
|
|
|
|
|
|
|
if (!Array.isArray(val) || !validateKey) { return void cb('EINVAL'); }
|
|
|
|
// Make a throttle or use the existing one to avoid calling
|
|
|
|
checkCheckpoints(val);
|
|
|
|
// storeCache with the same array multiple times
|
|
|
|
cache.setItem(id, {
|
|
|
|
t[id] = t[id] || Util.throttle(function (validateKey, val, onError) {
|
|
|
|
k: validateKey,
|
|
|
|
if (!allowed) { return void onError('NOCACHE'); }
|
|
|
|
c: val,
|
|
|
|
if (!Array.isArray(val) || !validateKey) { return void onError('EINVAL'); }
|
|
|
|
t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set)
|
|
|
|
checkCheckpoints(val);
|
|
|
|
}, function (err) {
|
|
|
|
cache.setItem(id, {
|
|
|
|
cb(err);
|
|
|
|
k: validateKey,
|
|
|
|
});
|
|
|
|
c: val,
|
|
|
|
|
|
|
|
t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set)
|
|
|
|
|
|
|
|
}, function (err) {
|
|
|
|
|
|
|
|
if (err) { onError(err); }
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, 50);
|
|
|
|
|
|
|
|
t[id](validateKey, val, onError);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|