Comparison
Cache invalidationvsTime to live
Cache invalidation
you changed the row and now you have to hunt down every cached copy of it before someone reads the old one.
The problem of removing or updating cached entries once the underlying data changes. It is hard because the set of cache keys derived from one row is rarely obvious: a single user update can invalidate their profile, three list pages, a search result and a rendered fragment. Most production bugs blamed on caching are really a key you forgot to invalidate.
Full entry →Time to live
you let the cached value expire after a fixed number of seconds instead of trying to work out exactly when it stopped being true.
An expiry stamped on a cache entry, after which it is treated as absent. TTL trades correctness for simplicity: you accept being wrong for up to the TTL in exchange for never having to reason about invalidation. Uniform TTLs on a batch of keys written together will expire together, which is one of the common ways to build yourself a stampede.
Full entry →