@thi.ng/cache
Version:
In-memory cache implementations with ES6 Map-like API and different eviction strategies
25 lines (24 loc) • 479 B
JavaScript
import { LRUCache } from "./lru.js";
class MRUCache extends LRUCache {
empty() {
return new MRUCache(null, this.opts);
}
resetEntry(e) {
this.items.asHead(e);
return e.value.v;
}
doSetEntry(e, k, v, s) {
if (e) {
this.opts.update?.(k, e.value.v, v);
e.value.v = v;
e.value.s = s;
this.items.asHead(e);
} else {
this.items.prepend({ k, v, s });
this.map.set(k, this.items.head);
}
}
}
export {
MRUCache
};