@thermopylae/lib.cache
Version:
19 lines (18 loc) • 583 B
JavaScript
import { BaseLFUEvictionPolicy } from "./lfu-base.js";
class LFUDAEvictionPolicy extends BaseLFUEvictionPolicy {
cacheAge;
constructor(cacheMaxCapacity, cacheBackendElementsCount) {
super(cacheMaxCapacity, cacheBackendElementsCount);
this.cacheAge = 0;
}
get initialFrequency() {
return this.cacheAge;
}
computeEntryFrequency(_entry, entryScore) {
return entryScore + this.cacheAge + 1;
}
onEvict(frequencyOfTheEvictedEntry) {
this.cacheAge = frequencyOfTheEvictedEntry;
}
}
export { LFUDAEvictionPolicy };