educative.io

Educative

Cache: when loading dynamic values in cache from database how to check latest data?

When loading dynamic entries in cache from database hoe to check latest data?
For example I use relational database in my back end and caching responses along the way. Suppose the result for particular request is cached but its values in database changed. How come cache knows the cached entry is outdated?

@Vinoth_Gopu Dynamic data stored in the cache has an expiry time or a TTL. After the TTL ends, the data is purged from the cache, and the newly updated data is stored in it. Besides if you are caching the data along the way (write-through caching strategy), as you said, the data in the cache will always be latest.