Consider adding a way to discard a certain number of caches
tbontb-iaq opened this issue · 3 comments
tbontb-iaq commented
Add a method to remove the n
most recently unused items.
One possible implementation:
function remove(this: QuickLRU<unknown, unknown>, n = 1) {
this.resize(this.size - n);
this.resize(this.maxSize);
}
Or using entriesDescending
instead:
function remove(this: QuickLRU<unknown, unknown>, n = 1) {
Array.from(this.entriesDescending())
.slice(0, n)
.forEach(([k]) => this.delete(k));
}
Or manually unroll the iterator using a loop.
sindresorhus commented
I would go with the first one. I would need a better name.
tbontb-iaq commented
How about drop
or discard
?
sindresorhus commented
I would go with evict
, but that's still too ambigious. It also need to say what it's evicting.