{"canonical_url":"https://engineer.company/glossary/http-cache-control/","content_markdown":"# HTTP Cache-Control\n\n## What it is\n\nHTTP Cache-Control is a header that carries rules for storing and reusing HTTP\nresponses. A server can give a browser a freshness lifetime for a response. It\ncan allow a shared cache to use a response or tell caches to check with the\norigin before reuse. A client can also put directives on a request to\ncommunicate particular requirements to caches along the path.\n\nFreshness tells a cache how long it can use a stored response without checking\nagain. A `max-age` value gives the freshness lifetime in seconds. A cache can\nstore a response with an unqualified `no-cache` directive and needs successful\nvalidation before reusing it. A response with `no-store` instructs caches to\navoid storing the request or the response. An unqualified `private` directive\nprevents shared caches from storing the response. A private cache such as the\nbrowser's can store it when the other applicable rules allow it. These\ndistinctions matter when a service has public assets alongside account-specific\npages.\n\nA validation step can use a validator such as an ETag. If the stored\nrepresentation is still current, a server can reply with status 304 and let a\nrecipient reuse its stored body. The cache's rules also depend on its stored\nresponse and the request it received for that copy. Vary can tell intermediaries\nwhich request headers affect the selection of a representation.\n\n## Why it matters\n\nStatic files can be delivered quickly when readers use a recent local copy. A\nstylesheet whose path includes a strong content fingerprint can use a long\nfreshness period, because different bytes should receive a different address.\nThe HTML that names it can follow a shorter policy or require validation so that\na reader learns about a new asset after a release. The two responses support\ndifferent responsibilities in the same page load.\n\nA public document and an account-specific page also carry different\nconsequences. A shared cache can deliver one public representation to many\nusers. A private response may contain data intended for one reader. Choose the\nstorage rule before deploying, and verify the response headers at the public\nboundary where browser and proxy behaviour meets. Include the actual requests\nand authentication state the service supports.\n\nA cache can also prolong an operational failure if an error message is stored as\nthough it is useful content. Decide which responses can be cached and for how\nlong. An origin can recover while a client still sees an earlier response. Make\nit possible to identify the served age, the cache involved and the headers that\nexplain what happened.\n\n## What it looks like in practice\n\nConsider a company website that links an HTML article to a generated PDF and a\nversioned stylesheet. A release changes the stylesheet's bytes and publishes a\nnew address for them. The page's cache policy gives returning browsers a reason\nto retrieve or validate the new HTML promptly. The old stylesheet still exists\nat its old address for readers holding the earlier document. A test can load\nboth versions and check the public response for each file.\n\nExercise more than one client state. A fresh client should receive the current\nasset references. A returning client with the earlier article should learn when\nthat representation changed. A request for an account page, if present, should\nreceive the policy designed for its private information. Inspect the headers\nafter any CDN or reverse proxy, then confirm what each cache actually reuses.\n\nEngineer's\n[small-server case study](/portfolio/a-whole-company-on-one-small-server/)\ndescribes operating public services within a constrained host. It provides a\npractical reason to consider which responses can be reused safely across\nrepeated visits. The illustrated cache policy explicitly protects the connection\nbetween a current document and the assets it names. Measure the resulting\ndelivery experience as well as the reduction in requests to the origin.\n\nRetain a command or browser replay for a release. Record the response status,\npolicy and current revision on the representative routes. If a cache has a\nstored copy, show why it may reuse it and when it must check again. A direct\nresponse inspection can distinguish a policy error from an outdated resource\naddress.\n\n## Where it goes wrong\n\nA common error is giving the main document and fingerprinted assets an identical\nlong freshness period. A browser can keep the older document and its valid older\nstylesheet long after the application has published a replacement. Put the\nappropriate policy on each response type and verify the production headers. Test\nthe returning-reader path because a clean browser cache cannot show what that\nreader sees.\n\nA response can also vary with a request header while its cache key treats the\nvariants as interchangeable. If a route serves different representations by\nmedia type or content encoding, use the relevant cache selection rule. Test the\nsame URL with two supported requests in an order that exposes a wrong reuse.\nRepeat the check at any shared layer that can store the response.\n\nPlan how a changed policy reaches clients that already hold a stored response. A\nnew header affects readers when they receive it. A still-fresh copy can remain\neligible under the policy it originally received. If a release relies on a new\nrepresentation becoming visible promptly, test the old policy state in the\nbrowser and the relevant shared cache. Keep the active document's identity\nobservable. A versioned resource address offers another way for a new document\nto request the bytes it needs.\n\nFinally, exercise conditional requests and failures during the same rehearsal. A\nvalidation response should carry the information needed to continue using the\nstored representation. An error should have the intentionally selected storage\nbehaviour. The correct policy is the one operators can explain for the actual\npublic route and verify after an ordinary change or rollback.\n\n## Further reading\n\n- [RFC 9111 Cache-Control directives](https://www.rfc-editor.org/rfc/rfc9111.html#section-5.2).\n  Defines the HTTP request and response directives.\n- [Mozilla's Cache-Control documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control).\n  Provides examples of freshness, storage and validation rules.\n- [Caddy's header directive](https://caddyserver.com/docs/caddyfile/directives/header).\n  Explains how to configure response headers on a web server.\n\n\u003chttps://engineer.company/glossary/http-cache-control/\u003e\n","date_modified":"2026-11-25T07:18:46Z","description":"Rationalise how browsers and shared caches handle a page, a versioned asset and a personalised response.","formats":{"gemtext":"https://engineer.company/glossary/http-cache-control/index.gmi","gopher":"https://engineer.company/glossary/http-cache-control/gophermap","html":"https://engineer.company/glossary/http-cache-control/","json":"https://engineer.company/glossary/http-cache-control/index.json","markdown":"https://engineer.company/glossary/http-cache-control/index.md","pdf":"https://engineer.company/glossary/http-cache-control/index.pdf"},"kind":"page","language":"en","title":"What is HTTP Cache-Control?","url":"https://engineer.company/glossary/http-cache-control/","version":1}