Skip to content
Web systems

Cache invalidation, without the folklore

A cache is a copy with an expiry story. Here is how to choose one that fits the data.

Community contributor8 min readQuick checkSources

A cache stores a result somewhere cheaper to reach than its original source. It can be a browser, a CDN, an application process, or a database page cache. The speed comes from reusing a previous answer.

The hard part is knowing when the answer is stale

Imagine a campus map cached on your phone. If a lecture room changes, the map is useful only if it has a way to learn about the change. Every cache needs a freshness rule: a time limit, an explicit invalidation message, a version check, or a decision to tolerate stale data.

Three common strategies

Time to live (TTL) is simple: keep the copy for a fixed window. Write-through updates the cache when the source changes. Versioned keys make old copies unreachable by including the source version in the cache key. Each strategy trades freshness, latency, and coordination differently.

Quick check

A timetable changes once a semester, and a few minutes of staleness is acceptable. Which strategy is a good starting point?

Show answer

A short TTL is a practical starting point: it keeps the rule simple while bounding how long an old timetable can remain visible.

Sources

  1. 1.Caching · MDN · reference (opens in a new tab)
  2. 2.HTTP caching · web.dev · guide (opens in a new tab)

Was this chapter useful?

Editors read every answer.

Star this chapter

Each star goes once to every reader who improved this chapter.

Finished reading?

Mark it to keep your place in the course.