|
|
@ -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
|
|
|
|
|
|
|
|
// storeCache with the same array multiple times
|
|
|
|
|
|
|
|
t[id] = t[id] || Util.throttle(function (validateKey, val, onError) {
|
|
|
|
|
|
|
|
if (!allowed) { return void onError('NOCACHE'); }
|
|
|
|
|
|
|
|
if (!Array.isArray(val) || !validateKey) { return void onError('EINVAL'); }
|
|
|
|
checkCheckpoints(val);
|
|
|
|
checkCheckpoints(val);
|
|
|
|
cache.setItem(id, {
|
|
|
|
cache.setItem(id, {
|
|
|
|
k: validateKey,
|
|
|
|
k: validateKey,
|
|
|
|
c: val,
|
|
|
|
c: val,
|
|
|
|
t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set)
|
|
|
|
t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set)
|
|
|
|
}, function (err) {
|
|
|
|
}, function (err) {
|
|
|
|
cb(err);
|
|
|
|
if (err) { onError(err); }
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, 50);
|
|
|
|
|
|
|
|
t[id](validateKey, val, onError);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|