Cache-ControlCache-Control carries a list of directives that dictate caching behavior on both requests and responses. On a response it tells browsers, CDNs, and proxies how long and how to store and reuse the response. It is the de facto standard for HTTP caching policy.
The core concept is freshness. `max-age=3600` marks a response fresh for 3600 seconds, reusable without hitting the network. Once it goes stale, the cache revalidates with the server using `ETag`/`If-None-Match` or `Last-Modified`/`If-Modified-Since`; a 304 Not Modified refreshes the cache without resending the body.
Storage scope splits into `public` (shared caches allowed), `private` (private caches only), and `no-store` (must not store). Despite its name, `no-cache` does not mean 'don't store' but 'must revalidate before reuse' — a frequent confusion. `s-maxage` is a max-age applied only to shared caches (like a CDN), and `immutable` lets versioned static assets skip revalidation entirely for performance.
Cache-Control (relative time) takes precedence over the legacy `Expires` (absolute time) header and is more precise. When a response varies by request headers (Accept-Encoding, language, ...), pair it with `Vary` so caches don't serve the wrong representation.
Cache-Control: <directive>[, <directive>]*e.g. Cache-Control: public, max-age=3600, stale-while-revalidate=60
max-age=<seconds> | Max seconds the response stays fresh; after this it is considered stale. |
no-cache | May cache, but must revalidate with the server before reuse. |
no-store | Must not be stored in any cache; used for sensitive responses. |
public | May be stored by shared caches (CDN, proxy). |
private | Only private (browser) caches may store it; shared caches must not. |
must-revalidate | Once stale, must never be reused without revalidation. |
immutable | Content won't change while fresh, so skip revalidation (versioned assets). |
s-maxage=<seconds> | max-age for shared caches only; overrides max-age there. |
stale-while-revalidate=<s> | Serve a stale response briefly while revalidating in the background. |