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

Cache size #317

Closed devDalys closed 1 year ago

devDalys commented 1 year ago

Probably a stupid question, but how do I know what value to write in max for caching ? I use the plugin together with Strapi

isaacs commented 1 year ago

Not a stupid question at all, probably the most important question you could be asking when considering using a cache!

Unfortunately, it is one that I probably can't answer for you, as I've never heard of Strapi and don't know what your app is doing, or what environments it exists in.

Lru-cache gives you a lot of flexibility in how you use it, but that's a double-edged sword, because you need to tune the dials yourself. Some questions to maybe help get you thinking in the right direction about how to approach it:

There's no magic formula, unfortunately. Sometimes the best thing to do is just add a caching layer, and then watch what happens. Does your 99th percentile performance improve? Does your memory utilization stay reasonable? If you tune the size or the TTL, does that make things better/worse/unchanged? The sweet spot might vary, or even be pretty unexpected. Observability tools can make a world of difference.

Hope that helps!