What is Cache Invalidation

Cache invalidation is the process of removing or updating entries in a cache when the underlying data changes, so that consumers do not receive stale data.

How it works

There are several invalidation strategies:

  • TTL (Time To Live) — entries expire automatically after a fixed duration. Simple but the data is stale for up to the TTL period.
  • Event-based — when data changes, the data owner publishes an event and the cache subscriber deletes or updates the relevant key. Fast invalidation, more complex to implement.
  • Manual purge — an operator or deployment script explicitly clears cache entries. Used during deployments or to fix incorrectly cached data.
  • Versioned keys — include a version in the cache key (user:42:v3). On schema or data changes, increment the version. Old entries expire naturally.

Why it matters

"There are only two hard things in computer science: cache invalidation and naming things." Serving stale data causes bugs that are difficult to reproduce — the data looks correct most of the time, but occasionally shows an old value. Users see outdated prices, stale inventory counts, or old profile data.

Getting invalidation right is the difference between a cache that is invisible (correct, fast) and one that causes hours of debugging.

For all cache patterns and invalidation strategies, see How Caching Works.