Home » HTTP Caching: Cache-Control, ETags, and Revalidation

HTTP Caching: Cache-Control, ETags, and Revalidation

Browser and stored cache response linked to an origin server by a dashed revalidation loop.

Choose a cache policy by deciding who may reuse a response, how long it can be reused without checking, and how a cache can confirm that an older copy is still valid. Cache-Control governs storage and reuse; an ETag identifies a representation for conditional requests. Neither replaces authorization.

A public documentation index and a signed-in user's export list should not inherit the same policy merely because both endpoints return JSON. Start with the information boundary, then choose the freshness budget.

Separate storage from permission to reuse

RFC 9111 defines the response directives. A useful initial distinction is:

Directive Decision it expresses
max-age=60 A freshness lifetime of 60 seconds, subject to the response's current age and other rules
no-cache Store if otherwise allowed, but validate before using the stored response to satisfy another request
no-store Do not store this exchange in a compliant cache
private A shared cache must not store the response; a private cache may, subject to other rules

These are different decisions. no-cache does not mean “never retain bytes.” no-store is not an encryption mechanism and does not retroactively erase copies already saved elsewhere.

For a public reference endpoint, an illustrative policy might be Cache-Control: public, max-age=60. That explicitly allows shared-cache reuse; it is inappropriate for personalized data unless the entire caching design establishes safe separation. For sensitive account output, no-store may be the appropriate starting point. A personalized response that may be retained privately but must be rechecked could instead use private, no-cache.

The MDN caching guide explains the distinction between private and shared caches and practical header combinations. Check the CDN or reverse proxy too: application headers, edge rules and browser behavior are separate places where a policy can be changed.

Follow one representation through revalidation

Consider this constructed exchange for a public catalog:

HTTP/1.1 200 OK
Cache-Control: public, max-age=60
ETag: "catalog-v7"
Content-Type: application/json

{"revision":7}

After that stored response becomes stale, the cache can ask whether its representation still applies:

GET /catalog HTTP/1.1
If-None-Match: "catalog-v7"

If the selected representation still matches, the server can return 304 Not Modified without retransmitting its body. If it changed, the server returns the current representation and validator. This conditional-request behavior is specified in RFC 9110.

The string catalog-v7 is illustrative. A real validator must follow the representation it identifies, including the application's content negotiation. Treat it as an opaque validator, not as a timestamp clients can invent or increment themselves. The ETag reference also distinguishes weak and strong validators; byte-for-byte identity and semantic equivalence are not interchangeable promises.

Revalidation saves a body transfer when the representation is unchanged. It still involves a request. A fresh response can avoid that round trip, which is why freshness and validators solve complementary parts of the problem.

Match the cache key to the response

A cache key must distinguish responses that are not interchangeable. Content negotiation can require Vary, such as a response varying by Accept-Encoding. That header does not establish authorization or make personalized responses safe in a public cache.

Ask what changes the actual representation: query parameters, language, account, permissions, accepted media type and deployment version. Then inspect how each cache treats those inputs. A URL-only key in front of a user-specific endpoint is a different design from a private browser cache.

Caching also does not stabilize a moving collection. Our pagination guide addresses continuation while data changes; a cache can efficiently serve a response whose pagination assumptions are still wrong.

Verify the boundary before optimizing the hit rate

For a future integration test, request the endpoint twice, inspect freshness and age, then change the resource and exercise conditional retrieval. Repeat as two distinct users for private endpoints. Check that a response intended for one identity is never reused for another, including at the edge.

Also inspect a changed permission without a changed URL. The server must authorize a conditional request appropriately; possession of a validator is not proof of continued access.

Those checks are a proposed protocol, not a test performed against a live cache here. The HTTP exchanges above are synthetic. The useful outcome is an explicit reuse policy whose behavior can be observed at each layer, rather than a large hit-rate number with an unclear privacy boundary.

You may also like