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

Pre Expire Hook #57

Closed
eamonpenland opened this issue Nov 1, 2019 · 1 comment
Closed

Pre Expire Hook #57

eamonpenland opened this issue Nov 1, 2019 · 1 comment

Comments

@eamonpenland
Copy link

Im trying to implement a delayed queue. I was thinking I could maybe add items into the cache with a ttl, and before expiration get a pre-expire or pre-evict callback to do what I need to do with the items. It doesn't appear like this is supported. Any ideas?

@cabol
Copy link
Owner

cabol commented Nov 3, 2019

Yeah, unfortunately, that's not supported for the current adapters, it is very specific and also depends on the cache and adapter implementation. There might be caches that give you that information via events (subscriptions), and normally they tell you when a key expires, but not X period of time before it expires. So, for this specific use case you have to implement something at the application level. For example, using a pre-hook, you can pattern-match the gets with the key you want, and check if that key is gonna expire soon or not and then apply your custom logic, but of course, it is a logic that will be performed every time you do a get. For more info, you can check this section about pre/post hooks.

On the other hand, do you want the "pre-expire hook or event" for all cached keys? If so, that could be a problem, imagine millions of keys across multiple nodes, it will generate significant traffic and maybe a bottleneck too, again, depending on the number of events the cache has to propagate across the network to different subscribers (it is something to consider too). Or you have a specific use case where you are interested in only a few/specific keys? If this is the case, that can be addressed easier.

@cabol cabol closed this as completed Nov 11, 2019
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