Skip to main content

Cache-Control

BothActive

Cache-Control directives control caching behavior in both requests and responses. It determines whether a response can be cached, for how long, and by whom – browser caches, CDNs, or proxy servers. The most important directives are max-age, no-cache, no-store, and public/private.

Cache-Control: <directive>[, <directive>]*

Description

The Cache-Control header holds directives (instructions) in both requests and responses – directives in requests are not necessarily the same as those in responses.

Directives

DirectiveDescription
max-age=<seconds>Response is fresh for this many seconds from when it was generated.
s-maxage=<seconds>Like max-age but applies only to shared caches (CDNs).
no-cacheMust revalidate with origin before using cached copy.
no-storeDo not cache at all. For sensitive data (banking, health).
publicResponse may be stored by any cache, including CDNs.
privateResponse is for a single user – only browser cache, not CDNs.
immutableResponse will not change during its freshness lifetime. Skip revalidation.
stale-while-revalidate=<seconds>Serve stale while fetching fresh in background.

Examples

Static asset (1 year)
http
Cache-Control: public, max-age=31536000, immutable
No cache (sensitive)
http
Cache-Control: no-store, no-cache, must-revalidate
CDN-friendly API
http
Cache-Control: public, s-maxage=60, stale-while-revalidate=600

Related

Specification

RFC 9111Cache-Control specification →