How about a handler that comes along with the “key” of a cached object right before it will expire.
I’ll then could react accordingly, renew expire time, call a client etc…
How about a handler that comes along with the “key” of a cached object right before it will expire.
I’ll then could react accordingly, renew expire time, call a client etc…
How about creating a timer that works in tandem with your cache expiration policy and extends object’s life in cache when it is about to expire?
Wouldn’t work too good with dynamically generated content being cached.
I’d prefer an event driven style which also sounds more safe to me.
I see a big win in this because I could schedule future calls this way.
Let’s assume I’d like to push some object to a client. I store the object in the cache, set cache expiration time to 2 minutes and push a message to the client to inform, he could fetch new data. If the client does not fetch data within 2 minutes I’ll react to the “onPreCacheExpires” event, renew the expiration time + push again. This way I could easily accomplish push with delivery state.
I am not intending to diverge the conversation, but wouldn’t it be easier to store the object in DB in that case?
This would not suffice the use case.
I do save the objects to the database.
The cache is used to hold updates for certain users, not just “holding” data for no reason.
This seemed to me a very handy way to keep updating automatically smooth without too much database invocation.
Yes, i hear you. The event driven approach provides a lot of benefits. The cache system we have does not raise an event for us. We put your data in cache with the specified expiration and it just happens to clear itself. As a result, raising an event would require some kind of timer, which increases complexity…
How about programmatically creating timers to handle this case?
I’d then schedule a task, provide the cache key and progress whatever is needed.
Scheduling cloud functions at least would be sufficient.
So that one could define a timer and then have some API to change its schedule?
Not sure if I got you right. What I meant is:
In a cloud code function I’ll schedule a function to be called in 2 minutes. I need to provide a parameter to this function (cache key).
After 2 minutes the scheduled function is being called to check if the client pulled the data which was in the cache. If not, send a push message to the client and reschedule the “check task”…and so on
If the client eventually pulls the data I clear the cached object and will no longer reschedule the checking task.
The need here would be to programmatically schedule a cloud function + having the ability to send parameters to this function. (Some kind of delayed execution)
How about exposing PUB/SUB functionality of Redis?
It is possible. for a fee though… ))