No-Cache Does Not Mean No-Store: A Safer HTTP Cache Checklist
- Get link
- X
- Other Apps
No-Cache Does Not Mean No-Store: A Safer HTTP Cache Checklist
A useful HTTP cache can improve latency and reduce origin traffic, but a few misleading directive names are also a common source of accidental retention or stale pages. The most important distinction is simple: no-cache does not mean do not store. It means you may store this response, but it must be validated before reuse.
Start with the response, not the URL
Before setting cache headers, decide which cache layer may hold the response and how often its meaning may change.
- Immutable assets: Versioned files such as
/assets/app.3a8f2c.jscan usually stay fresh for a long time. - Mutable resources: HTML pages, API responses, and feeds change. They often benefit from short freshness periods or validation.
- Private resources: Account pages, authenticated API responses, or any body containing a user's information should be kept out of shared caches. A private browser cache may still be appropriate.
- Non-reusable resources: Password changes, one-time links, internal errors, and sensitive responses may need to remain uncached.
This classification is about the representation being served, not merely whether the path contains a number or a name.
Use validation for mutable HTML and data
The following is a conservative baseline for a document or endpoint that can change:
Cache-Control: no-cache, private ETag: "2026-11-30-v7" Vary: Accept-Encoding no-cache allows a cache to store the response but requires it to ask the origin whether a stored copy is still valid before reuse. With an ETag, the next browser request can use If-None-Match. If the representation has not changed, the origin can answer with 304 Not Modified instead of sending the body again.
Add private when a shared cache must not store the response. RFC 9111 allows private caches to store it, while shared caches must not reuse it. Do not assume private means “never stored anywhere”; it is a cache-sharing boundary.
Vary is equally easy to overlook. If the response changes by Accept-Encoding, Accept-Language, or another request header, the cache key must include that header or a cache may return the wrong representation to a different client.
Use no-store when the body must not be retained
For a response that contains credentials or user-specific secrets, use a stronger declaration:
Cache-Control: no-store Pragma: no-cache no-store instructs caches not to store the response. The Pragma: no-cache line is an HTTP/1.0 compatibility fallback, not a replacement for modern Cache-Control.
Be precise: no-store is a response policy. It does not magically erase copies already written to disk, logs, databases, or a CDN outside the cache headers' control. It also does not protect an application from authorization bugs or secrets disclosed in the response itself.
Give versioned assets a long freshness lifetime
For a fingerprinted asset that changes name whenever its bytes change, a long browser and shared-cache lifetime is practical:
Cache-Control: public, max-age=31536000, immutable The public directive permits shared caching; max-age defines freshness in seconds; and immutable tells the browser that the response will not change while it remains at this URL. These settings only make sense with content-addressed URLs. Do not apply a year-long max-age to /app.js if deploying a new build leaves that URL unchanged.
A five-minute cache review
- Capture the real response. Inspect the response headers with
curl -Ior browser developer tools. Check redirects as well as the final response. - Identify who may store it. Public assets may be shared; personalized responses should not be.
- Choose freshness or validation. Long
max-agefits immutable URLs.no-cacheplus ETag or Last-Modified fits mutable resources. - Check the cache key. Use
Varyfor meaningful content negotiation, and test language, encoding, and authenticated variants. - Verify behavior at both layers. Check browser reuse and CDN/proxy behavior separately. Include a cache hit, a cache miss, and a conditional
304in the test plan.
Use no-cache deliberately
The practical rule is to ask what happens when this response is reused? If reuse is safe for a known freshness period, set max-age. If reuse requires confirmation, use no-cache with a validator. If retention itself is unacceptable, use no-store. That distinction is small in syntax and large in operational impact.
References
- IETF RFC 9111: HTTP Caching
- MDN: Cache-Control
- web.dev: Prevent unnecessary network requests with the HTTP Cache
- MDN: Vary
- MDN: ETag
❤️ Support This Blog
If this post helped you, you can support my writing with a small donation. Thank you for reading.
- Get link
- X
- Other Apps

Comments
Post a Comment