Choose HTTP cache rules for API responses
HTTP caching stores a response in a browser or intermediary so it can be reused while fresh or revalidated when stale. First define which request variants may share a response, then express freshness and storage scope with Cache-Control. This guide follows RFC 9111 and RFC 9110; products may differ.
HTTP caching stores a response in a browser or intermediary so it can be reused while fresh or revalidated when stale. First define which request variants may share a response, then express freshness and storage scope with Cache-Control. This guide follows RFC 9111 and RFC 9110; products may differ.
Match cache key to response variants
A cache commonly selects by request method and target URI. If representation varies by request headers such as language, declare them with Vary (for example Vary: Accept-Language). A cache must not reuse a stored response for a request whose nominated header values do not match. Missing Vary can expose the wrong language or encoding. Vary: * does not match an ordinary request for reuse.
Freshness, revalidation, and directives
Cache-Control: max-age=60 means a response is fresh for 60 seconds. A shared cache uses s-maxage when present. Once stale, a cache may revalidate with ETag or Last-Modified; unchanged content can yield 304 Not Modified and reuse of the stored body. Freshness is a reuse window, not a promise that data did not change.
| Directive | Meaning |
|---|---|
max-age=N | Fresh for N seconds. |
s-maxage=N | Shared-cache freshness lifetime when present. |
private | No shared-cache storage; private cache may store. |
no-cache | May store, but validate before reuse. |
no-store | Do not store or reuse; not a complete privacy guarantee. |
private prevents shared-cache storage but can permit a private cache to store the response. no-cache permits storage but requires validation before reuse. no-store directs private and shared caches not to store or reuse the request/response, but is not a complete privacy guarantee. Do not infer meanings from directive names. Authorization does not automatically make every response uncacheable; apply RFC 9111 conditions.
Choose and verify a policy
List all response variants and set the needed Vary fields; choose private/shared cache scope; set an explicit lifetime or revalidation rule; check tenant and user boundaries; inspect Age, Cache-Control, Vary, ETag, and bodies through the actual browser/CDN/proxy path.
Design cache key, freshness, revalidation, and user boundary together. Verify real responses; a config file alone does not prove cache behavior.
[RFC 9111: HTTP Caching](https://www.rfc-editor.org/rfc/rfc9111.html)
[RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110.html)