how to keep caching up to date

Viewed 9661

when memecached or Redis is used for data-storage caching. How is the cache being updated when the value changed?

For, example. If I read key1 from cache the first time and it missed, then I pull value1 and put key1=value1 into cache.

After that if the value of key1 changed to value2. How is value in cache updated or invalidated?

Does that mean whenever there is a change on key1's value. Either the application or database need to check if this key1 is in cache and update it?

2 Answers

You can simply empty the particular cache value in the api function where insertion or updation of that particular value is performed. This way the server will fetch the updated value in the next request because you had already emptied the cache value.

Here is a diagram which will make it easier for you to understand: Redis Caching Architecture diagram

Related