-
Notifications
You must be signed in to change notification settings - Fork 138
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
Persisting node-cache #293
Comments
Seems technically possible. You could read all values with const success = myNodeCache.mset(Object.entries(loadedJsonObject).forEach(([key, value]) => {
{key: key, val: value.v, ttl: value.t}
})); This is most likely something others aren't doing with this library though. node-cache as far as I understand is meant only for caching temporary values. If you'd like long term data storage, I'd recommend something like If you do still want a extremely performant database with the ability to set ttl values that won't clear out every time you restart your program, you could use redis but it will be more complicated as it's a database ran separated from your script (like monngodb). It stores all data in memory, so it's very fast but the database it's self will clear out between restarts. You do not however need to restart the database every time you restart your program. It would be a solution that would make sense if the data you're storing doesn't need to be persisted, it would just be nice to have if it where between restarts. Otherwise, if some data needs to be persisted and other data does not need to be persisted, it is common practice to use a caching db like node-cache or redis in combination with a db built for persistence like jsoning or mongodb. That way all your temporary data can be stored in your caching database, and all the data that needs to persist can be stored in your persistent database. Don't feel like it's wrong to use 2 databases for 2 different purposes in that case. Let me know if you have any questions about that. I'll help you persist data between restarts of node-cache if you'd like, just know that's probably starting to reach outside of the intended use of the package. It will work though, so if that solution makes the most sense to you then go for it. Thought I'd just lay out other common solutions for you if you'd like to go for a more common/intended route |
I am currently using Thank you wholeheartedly for the detailed response; especially for the additional offer to help me find a solution! |
Awesome! Glad you found a good solution that fits your needs perfectly, good luck on your projects! |
I use |
Currently there are warnings after installed persistent-cache
Use with care. |
This is my implement persistent cache based on node-cache.
Usage:
I hope it is useful for you. |
I am using node-cache for a dead simple string key/val lookup & I'd like the cache to persist across server restarts.
Would it be possible, to save the cache to, for example, a JSON file which I read into node-cache on server initialization?
Is this something folks already use node-cache for, or shall I look elsewhere?
The text was updated successfully, but these errors were encountered: