Guskermitt
Guskermitt

Reputation: 254

Redis - Reload content before expires

In Akamai we can order to reload a content from origin when 90% of the expiration time was consumed. In this case, Akamai is serving the cached content but is accessing to origin to reload the new content.

Is there a similar feature in Redis?

For example, I put a content in cache for 5 hours. But I want to reload it if someone access to this content when only left 30 minutes or less. If a user access to it in this period I will serve the cached content but in background we will be reloading the new content.

Is it possible?

Thanks.

Upvotes: 1

Views: 1746

Answers (1)

mp911de
mp911de

Reputation: 18119

Redis is not an active component regarding fetching data itself but rather a data store. It keeps your data, expires/evicts keys based on their TTL.

You/your application is in charge to populate Redis with the data you want to keep stored.

However, you can use Redis primitives to achieve a part of what would be needed to serve your requirement:

Keyspace notifications publish a notification on certain events such as key creation or expiry. You could store two keys in Redis, a key representing your payload with the appropriate TTL and a phantom key which is a marker with a slightly shorter TTL (say 90% of the original TTL).

As soon as the phantom key expires you capture that notification. Then you can fetch the content of the cache you want to update. You update the cache key and write a phantom key again for the next cache update iteration.

The steps above are a strongly abbreviated but should guide you towards a feasible approach.

Upvotes: 6

Related Questions