PREP WITH PROOF
Menu
SOFTWARE ENGINEERING / PRACTICAL GUIDE

Cache-Control: private vs no-cache vs no-store

Choose HTTP cache response policies correctly. Compare private, no-cache and no-store with a runnable Python fixture and checks for browser, origin and CDN behavior.

THE QUICK ANSWER

private forbids shared-cache storage but permits private-cache storage. no-cache permits storage but requires successful validation before reuse. no-store prohibits storage of the covered request and response. Choose by storage audience and reuse requirements, then verify the actual cache layer.

Three directives answer different cache questions

A dashboard response belongs to one signed-in user, so a developer adds Cache-Control: private. Later, someone calls it a privacy bug because the browser reused that response without contacting the server. The header may have worked as specified: private restricts shared caches, not all caching.

Separate three questions before choosing a response policy. May the response be stored? May a shared cache store it? Must the cache contact the origin before using a stored copy? The unqualified response directives private, no-cache and no-store answer different parts of that decision. They are not three interchangeable ways to disable a CDN.

This guide discusses response headers, not directives on a client request. It also uses the unqualified forms: private and no-cache can take field-name arguments with more specialized semantics. Unless you deliberately need those variants and have verified support, use the simpler policy that expresses the endpoint's actual requirements.

Response directiveStorage meaningReuse meaning
privateA shared cache must not store it; a private cache mayOther freshness and validation rules still apply
no-cacheDoes not itself prohibit storageA stored response needs successful validation before reuse
no-storeA cache must not store the request/response covered by the directiveIt must not use that response for another request

Source: RFC 9111: HTTP cache storage, validation and response directives ↗

Choose a policy from the endpoint contract

For personalized content that may be retained by a browser but must be checked before reuse, private, no-cache is a useful combination. private restricts shared storage and no-cache requires validation. With an appropriate validator, the origin can confirm an unchanged representation with 304 instead of resending the body. A changed or invalid validator can result in a new full response.

For a response that should not be retained in HTTP caches, choose no-store. Adding private, no-cache and max-age=0 to it usually adds noise rather than a clearer basic storage policy. no-store is not encryption, access control or a promise that no copy exists anywhere. Application state, logs, screenshots and compromised clients are separate concerns.

For public content that is safe for shared reuse, choose explicit freshness that matches the resource. A versioned static asset can have a different lifetime from a public inventory response. Do not make a user-specific response public merely to improve a cache-hit graph; start with which recipients are allowed to receive it.

# Browser storage allowed, shared storage forbidden, validate before reuse:
Cache-Control: private, no-cache
ETag: "account-representation-v7"

# Do not retain this response in HTTP caches:
Cache-Control: no-store

# Public, explicitly fresh for a short interval:
Cache-Control: public, max-age=60

Source: RFC 9111: HTTP cache storage, validation and response directives ↗

No-cache can still produce a 304 response

no-cache requires validation before reuse; it does not require a full body download every time. A cache that stored a response and its ETag can send If-None-Match on a later request. If the origin confirms the representation is unchanged, a 304 response lets the cache reuse its stored body under the applicable rules.

max-age=0 and no-cache are related but not identical instructions. max-age controls freshness. no-cache explicitly requires successful validation for reuse. must-revalidate applies when the stored response is stale; it does not force a request for every reuse of an otherwise fresh response. Choose the directive that states the behavior you need rather than accumulating headers whose names sound restrictive.

If validation fails because the origin is unavailable, a no-cache response cannot simply be reused as though validation succeeded. Diagnose the validation path and the client's error behavior. If the server always sends a full 200 response, check whether the client retained a validator and whether the origin evaluates it correctly.

Source: RFC 9111: HTTP cache storage, validation and response directives ↗

Run a local HTTP fixture for all three policies

Save the following Python standard-library script and run it with python3. It starts a loopback origin on an ephemeral port and makes two logical requests for each of three resources through two small cache instances: one personal and one shared. Assertions check storage eligibility, body reuse and the number of origin requests.

The fixture intentionally understands only its three fixed policies and immediate reuse by the same identity. It does not implement a general HTTP cache, expiration calculations, Vary, authorization rules or full 304 metadata updates. Its value is a reproducible comparison of these specific decisions. It does not measure how a browser, proxy or CDN is configured.

The no-cache cases retain a body, validate using the stored ETag, receive 304 and return the saved bytes. The no-store cases contact the origin twice and retain no entry. The shared cache also retains no private response, while the personal cache can immediately reuse that fixture's private, max-age=60 response.

import http.client
from http.server import BaseHTTPRequestHandler, HTTPServer
from threading import Thread

class Origin(BaseHTTPRequestHandler):
    calls = 0
    policies = {
        "/private": "private, max-age=60",
        "/revalidate": "no-cache",
        "/no-store": "no-store",
    }
    def log_message(self, *args):
        pass

    def do_GET(self):
        type(self).calls += 1
        policy = self.policies.get(self.path)
        if policy is None:
            self.send_error(404)
            return
        unchanged = self.headers.get("If-None-Match") == '"v1"'
        body = b"example representation"
        self.send_response(304 if unchanged else 200)
        self.send_header("Cache-Control", policy)
        self.send_header("ETag", '"v1"')
        if not unchanged:
            self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        if not unchanged:
            self.wfile.write(body)

class FixtureCache:
    # Only the fixture's three policies, fixed identity and immediate reuse.
    # No general freshness, Vary, authorization or 304 metadata-merging logic.
    def __init__(self, shared, port):
        self.shared = shared
        self.port = port
        self.entries = {}

    def get(self, path):
        saved = self.entries.get(path)
        if saved and "no-cache" not in saved["policy"]:
            return "CACHE", saved["body"]
        headers = {"If-None-Match": saved["etag"]} if saved else {}
        conn = http.client.HTTPConnection("127.0.0.1", self.port, timeout=2)
        try:
            conn.request("GET", path, headers=headers)
            response = conn.getresponse()
            status = response.status
            body = response.read()
            policy = response.getheader("Cache-Control")
            etag = response.getheader("ETag")
        finally:
            conn.close()
        if status == 304:
            assert saved is not None
            return 304, saved["body"]
        assert status == 200
        allowed = "no-store" not in policy and not (
            self.shared and "private" in policy
        )
        if allowed:
            self.entries[path] = {"body": body, "etag": etag, "policy": policy}
        return status, body

server = HTTPServer(("127.0.0.1", 0), Origin)
thread = Thread(target=server.serve_forever, daemon=True)
thread.start()
try:
    for shared in (False, True):
        for path in Origin.policies:
            cache = FixtureCache(shared, server.server_port)
            before = Origin.calls
            first = cache.get(path)
            second = cache.get(path)
            assert first[1] == second[1] == b"example representation"
            expected = (
                "CACHE" if path == "/private" and not shared else
                304 if path == "/revalidate" else 200
            )
            assert second[0] == expected
            expected_calls = 1 if expected == "CACHE" else 2
            assert Origin.calls - before == expected_calls
            if path == "/no-store" or (shared and path == "/private"):
                assert path not in cache.entries
            label = "shared" if shared else "personal"
            print(label, path, "second:", second[0], "origin calls:", expected_calls)
    assert Origin.calls == 11
finally:
    server.shutdown()
    server.server_close()
    thread.join()

Read cache reuse and origin traffic separately

The tested fixture makes twelve logical cache calls but eleven origin requests. Only the immediately fresh personal private response avoids its second origin request. Both no-cache cases contact the origin again yet avoid a repeated body transfer by using 304. A dashboard that counts only full response bodies can therefore tell a different story from one that counts origin requests.

These are the script's observed results, not production performance claims. A real cache might not store an eligible response, and additional rules can prevent reuse. Permission to cache is not a requirement to cache. To test a real endpoint, preserve the request context and inspect the actual response headers, validator exchange and cache layer.

personal /private second: CACHE origin calls: 1
personal /revalidate second: 304 origin calls: 2
personal /no-store second: 200 origin calls: 2
shared /private second: 200 origin calls: 2
shared /revalidate second: 304 origin calls: 2
shared /no-store second: 200 origin calls: 2

Source: RFC 9111: HTTP cache storage, validation and response directives ↗

Inspect the deployed GET path before changing policy

Use a non-sensitive endpoint or a controlled test account and capture the headers actually delivered by a GET. curl does not act as a browser response cache by default, so repeating a curl command is useful for observing headers but does not alone test private-cache reuse. The command below discards the body and prints headers; it still sends a GET.

Inspect every relevant layer: origin, reverse proxy and CDN. Check for duplicate or conflicting Cache-Control fields and whether a framework or edge rule changes the policy. A response from the public hostname can differ from one obtained directly at the origin. If a provider supplies a cache-status header, use its documented meaning and compare it with Age and the response's own policy.

Cookies are not a general substitute for an explicit storage policy. Shared-cache handling of authenticated requests also has additional rules, so do not assume an Authorization header and a cookie receive identical treatment. For a personalized endpoint, state the intended policy and test requests from distinct users without exposing real private content in the evidence.

# Replace with an endpoint you are authorized to inspect.
# No authentication material is included in this example.
curl --silent --show-error --dump-header - --output /dev/null   https://example.com/status

Source: RFC 9111: HTTP cache storage, validation and response directives ↗

A new header is not a universal purge command

Deploying no-store changes what a recipient should do with that response. It is not a universal instruction that instantly removes every older response previously stored under a different policy. A fresh old entry might still be served without reaching the newly configured origin. Use the cache provider's supported invalidation process when correcting an existing shared-cache exposure, and verify that the affected key and variants were removed.

Also distinguish HTTP response caching from navigation restoration and application-managed storage. A page appearing when the user presses Back is not sufficient evidence that a shared HTTP cache stored it. Inspect the actual request and the layer responsible. If an application saves response data in its own state or storage, evaluate that path separately.

If a response crossed user boundaries, first contain the exposure and review the affected cache keys, variants and recipients. Changing Vary can help separate legitimate representations, but it does not replace a policy that forbids shared storage. A user-specific response should not depend on an accidentally unique key to remain private.

Source: RFC 9111: HTTP cache storage, validation and response directives ↗

Verify the policy using the behavior it promises

For private, confirm that the shared layer does not store the response, then separately test the allowed private-cache behavior. For no-cache, verify that reuse triggers validation and that a successful 304 preserves the correct body. For no-store, verify that your controlled cache does not retain the response, and investigate any application storage that remains.

Record the deployed headers, the request identity, the cache layer and the observed exchange together. Keep cache-hit counts, origin-request counts and body-transfer counts separate. The result you want is a response lifecycle that matches the endpoint's privacy and freshness contract, not a particular status code or a maximized hit rate.

Source: RFC 9111: HTTP cache storage, validation and response directives ↗

KEEP THESE THREE THINGS

Your next steps

  1. Separate whether a response may be stored from whether it may be reused without validation.
  2. A no-cache response can be stored and reuse its body after a successful 304 validation.
  3. Check deployed headers and existing cache entries; a new no-store response is not a universal retroactive purge.

Sources & official resources

Linked resources checked on 2026-11-12. Technical behavior and provider guidance can change; check the documentation for the version you use.

About this guide and its recommendations

Published by Prep With Proof with AI-assisted drafting. Study routines and examples are editorial suggestions, not official exam instructions or claims of a learner's personal results. Cited provider facts are linked; ownership of recommended Prep With Proof products is disclosed. No competitor endorsement or guaranteed certification outcome is implied.

Suggest a correction →