In this story

A cache stores an answer so you don’t have to compute or fetch it again. The interesting question is what you’re promising the person who receives that old answer.

A fingerprinted stylesheet and an account balance shouldn’t use the same freshness policy. The stylesheet’s URL can change when its contents change. The balance represents a moving state that a reader may act on.

Decide what can be reused

Start with the resource and its audience. Is the response public? Does it vary by user, language, or some request header? How long can an old value remain useful?

The cache key has to distinguish responses that aren’t interchangeable. A response associated with one person’s session must not be served to someone else. So get the key right before you worry about expiry times.

Freshness and validation are different

For HTTP caching, a response can be considered fresh for a specified period. After that, a cache may ask the origin whether its copy is still current. An unchanged response can be validated without transferring the full body again.

Cache-Control: no-cache allows storage but requires validation before reuse. no-store instructs caches not to store the response. Those names are easy to misread. MDN’s HTTP caching guide (opens in a new tab) explains the directives and the role of validators such as ETags.

Make invalidation part of publishing

For an immutable asset, putting a content hash in the filename gives each version its own address. A new page can reference the new asset while older pages still reference the old one. That turns invalidation into a naming problem, which is much easier to solve.

An article at a stable URL needs a different policy. Readers may tolerate a short delay after a small edit, but a correction should have a predictable path to the edge and browser. Document that path before the first urgent correction.

Look at the miss path too

A cache hit is only part of the system. What happens when many entries expire together? Can concurrent misses repeat the same expensive work? Does the origin have enough capacity when the cache is cold?

A useful cache policy explains what is stored, who may receive it, when it is fresh, and what happens when it isn’t. Write that down before you tune anything for speed.