-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Would be great to have a TTL #16
Comments
+1 |
You can just do this in your own cache handler, no need to extend fast-memoize for this. |
Combining it with 2 other packages you can actually set both the max number of items in the cache and a TTL without the need to change anything on 'fast-memoize'.
Update: it seems that I was wrong and that the above works only with my particular setup. Indeed I have a local fork of the package that I made async/await to match my needs. Now that I cloned the package and try the tests I see that they're not working for my setup unless I make it async/await and await the memoized functions in my code. So it's better to dismiss my previous suggestion. If I find the time I may investigate more deeply how to make the test works. In the meantime if someone is curious these are the lines I changed in the package:
This is how I call my memoized functions
Update 2: Here there is a working fork that handles both standard and async cache as well as async functions |
@ecerroni could you explain how to use TTL in your fork? I looked at the code and don't see any handling of TTL with options ... Thanks |
|
That way cache entries will automatically expire and not explode memory usage. This is especially important on the server.
This would likely involve you keeping a separate "shadow cache" that kept the created times of the cacheKeys.
Obviously this would be fractionally slower so a simple opt-in (by say
{TTL: [any non-zero value in ms]}
in the options) to this code path is probably all you need.If you're interested I can submit a PR ;)
The text was updated successfully, but these errors were encountered: