isaacs / node-lru-cache

A fast cache that automatically deletes the least recently used items
http://isaacs.github.io/node-lru-cache/
ISC License
5.38k stars 353 forks source link

Advice on avoiding fetches being aborted due to eviction #320

Closed FINDarkside closed 1 year ago

FINDarkside commented 1 year ago

Is there some best practice way to use this that would avoid the following issue:

When you use fetchMethod with max option and get max+1 fetches at the same time, one of the fetches is aborted because it's evicted. This isn't really the behaviour I'd need, it would be fine if I just get the result and after that it's evicted from the cache. Obviously I could stop using fetchMethod and just use get and set, but then I'd also need to handle not firing multiple fetches concurrently for the same key. Meaning that I'd reimplement some of the functionality that already exists in this library. And if I wanted to use staleWhileRevalidate I'd have to implement that one as well instead of using the functionality from lru-cache.

isaacs commented 1 year ago

Are you looking for ignoreFetchAbort?

https://github.com/isaacs/node-lru-cache#ignorefetchabort

FINDarkside commented 1 year ago

Ahh thank you! And sorry, I thought I had read all the options carefully. :pray:

isaacs commented 1 year ago

No apology necessary, this module has too many options. I had to look it up myself lol