CacheFactory
CacheFactory copied to clipboard
onExpire does not return the value of the cached item if storage is not in memory
The following returns the value of the cached item only if it is present in the expiresHeap
:
{
key: 'removeExpired',
value: function removeExpired() {
// ...
while ((expiredItem = this.$$expiresHeap.peek()) && expiredItem.expires <= now) {
expired[expiredItem.key] = expiredItem.value ? expiredItem.value : null;
this.$$expiresHeap.pop();
}
// ...
if (this.$$onExpire) {
Object.keys(expired).forEach(function (key) {
_this6.$$onExpire(key, expired[key]);
});
}
// ...
}
}
However, the heap will only contain the value if you're using in-memory storage:
{
key: 'put',
value: function put(key, value) {
// ...
if (this.$$storage) {
// ...
this.$$expiresHeap.push({
key: key,
expires: item.expires
});
} else {
// ...
this.$$expiresHeap.push(item);
// ...
}
// ...
}
}
Ideally, it should work regardless of what storage option you use e.g. local storage.