Skip to content
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

Memory store: how to set the max value to infinite (only allocate memory on new items) #632

Closed
Thomas-1985 opened this issue Dec 30, 2023 · 4 comments
Labels

Comments

@Thomas-1985
Copy link

Hello,

npm version: 5.3.2
Node.js version: 16.16.0
Typescript: 5.3.3

I use cache-manager in my project and i want to use the builtin memory-cache. I don't want expiration of keys so i set ttl: 0.
However, i also don't know in advance how much cache entries there are. When i set the max value too low, i cannot save all values, when i set it too high, the node process runs out of memory (i think the memory is allocated when the cache-manager instance is created).

How can i solve this (i want that the cache size grows automatically when new values are added)?

Best,
Thomas

@jaredwray
Copy link
Owner

Hi @Thomas-1985 - first, I would highly recommend that you do set a ttl as that is what is best practice and you will hit the issue of running out of memory.

If you are only doing in memory and dont want to set the max just use a standard LRU type cache and do a calculation on the size of the server and the objects you are putting in.

@Thomas-1985
Copy link
Author

But how can i avoid setting a ttl if the cache should be persistent? In my case, it is filled upon startup of my app and updated if neccessary. In other cases the data doesn't change and has to be up to date in the cache, thats why i didn't set a ttl (and also because filling the cache takes some time).

@jaredwray
Copy link
Owner

If you dont want to set a ttl just use Map()

@Thomas-1985
Copy link
Author

Thomas-1985 commented Jan 3, 2024

But if i want to use your module (because of the different cache engines) and set a max but don't set a ttl, will it then run out of memory (in this case i don't understand why - please explain)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants