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

Where to use load/2, dump/2 #201

Closed
benonymus opened this issue Apr 21, 2023 · 4 comments
Closed

Where to use load/2, dump/2 #201

benonymus opened this issue Apr 21, 2023 · 4 comments

Comments

@benonymus
Copy link

benonymus commented Apr 21, 2023

Hey,

I am wondering about where to use load and dump from.
https://hexdocs.pm/nebulex/Nebulex.Cache.html#c:load/2
https://hexdocs.pm/nebulex/Nebulex.Cache.html#c:dump/2

Would I add init (load) and stop (dump) (in a genserver terminate analogous way) in the Cache module? - this did not seem to work for stop
What is the recommended way?

Thanks

@cabol
Copy link
Owner

cabol commented Apr 26, 2023

This is a good/interesting question. The dump/load commands are mainly meant for running on-demand and be invoked from your application. For example, you may have a job/process/gen_server in your app that runs from time to time (or when there is a graceful shutdown you could dump the data before stopping the app) and calls the dump command to take a snapshot of the cache, and another job/process/gen_server that runs when the app starts and tries to restore the cache from a file by calling the load command. Certainly, this is a very naive approach that won't avoid losing data but at least will avoid losing everything. However, there may be situations you don't want to lose any data, in that case, the adapter should provide also persistence, like Redis for instance, you can configure it for persisting data, but this is on the adapter side. Let me know if that helps, I stay tuned, thanks!

@benonymus
Copy link
Author

Hey,

Thanks for the response.
In this case the main goal is to achieve a sort of pass-over between deployments just to cover edge cases.
I did what you mentioned too, added a process that starts after the cache and upon shutdown it dumps the cache to a file and on startup it loads it. Seems to achieve what I was looking for here.

Thanks!

@benonymus
Copy link
Author

benonymus commented Apr 26, 2023

How would I achieve data persistence? Which adapter offers that? Or you meant that for Redis only?

@cabol
Copy link
Owner

cabol commented Apr 26, 2023

Right, currently the only adapter that offers data persistence is the Redis adapter, because of Redis itself, you know Redis provides support for persistence already, so I'd say more than the adapter is Redis, you can configure it for data persistence.

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

No branches or pull requests

2 participants