planttheidea/micro-memoize

Infinite caching?

Offirmo opened this issue · 4 comments

Hi and thanks for the great lib! Greatly boosted my app which is built around immutability but has expensive computations.

How do we get an infinite caching? maxSize: Number.POSITIVE_INFINITY ?

That would be my recommendation! I used the same trick to provide infinite caching on moize (a wrapper around this library that handles more use-cases out of the box, but has a larger footprint).

Thanks @planttheidea for the answer! So you're confirming it should work?

Or should one use Number.MAX_SAFE_INTEGER for safety?

To answer your second question, either one should be fine. Realistically speaking neither one will ever be hit, and practically speaking I would actually recommend a number that is not as absurdly high as the maximum safe integer but still pretty high (arbitrary choices ... 100? 500? 5000?) to cap on potential leaks. This was a driving factor to why moize changed its default cache size from Infinity to 1 in v6; infinite cache creates easy leaks unless you have tight controls. Take my opinion with a grain of salt, though. :)

But to answer your first question, Infinity should work just fine. If you have trouble, let me know your repro steps and I can check it out.

Hi, thanks for the time and explanations!

FYI my use case is a command line tool doing a specific task. Once the task is done, the tool exits, so I don't mind such a "memory leak" for now.