sindresorhus/quick-lru

Consider adding a way to discard a certain number of caches

tbontb-iaq opened this issue · 3 comments

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.

I would go with the first one. I would need a better name.

How about drop or discard?

I would go with evict, but that's still too ambigious. It also need to say what it's evicting.