This article contains no advertising or affiliate links. As of July 29, 2026, we checked HTTP caching against RFC 9111 and RFC 9110, additional directives and observation headers against relevant RFCs, and implementation details against official Mozilla MDN, Chrome, Cloudflare, and Google documentation.
Caching is more than temporarily storing data: it is a way to control which stored result may be reused, when, for whom, and under what conditions. Used well, it can speed up page loads and reduce server load and data transfer. Incorrect keys or update procedures, however, can result in stale information or responses intended for another user being served.
A cache is defined by reuse conditions, not just stored copies
A web cache stores responses to requests and reuses them directly when the cache key matches and the response is fresh. Even after it becomes stale, an ETag or other validator can confirm that it has not changed, allowing reuse after a 304 response without retransmitting the body.
| In one sentence | A way to store past responses or calculations and reuse them later under the same conditions |
|---|---|
| Main benefits | Reduce page load time, origin load, data transfer, and processing costs |
| Basic decision | Matching cache key → HIT if fresh, revalidate if stale, MISS if not stored |
| Important headers | Cache-Control、ETag、Last-Modified、Vary、Age、Cache-Status |
| Greatest risks | Showing stale data for too long or mistakenly serving personalized responses from a shared cache |
| Safe updates | Use versioned URLs for static files, short freshness or revalidation for HTML and APIs, and targeted purges in emergencies |
A cache stores results for reuse in later operations
In computing, a cache speeds up later operations by keeping data that takes time to fetch or calculate closer to where it is needed or in faster storage. Examples include CPU, DNS, browser, CDN, and database query caches.
This article focuses on web caching. In HTTP caching as defined by RFC 9111, a response to a request is stored and reused to answer subsequent requests. More important than the stored data itself are these four points:
Key
Identify which requests can use the same response based on URL, method, query, language, compression, and other factors.
Freshness
Set how long a stored response may be reused without validation, using max-age or s-maxage for shared caches.
Revalidation
Use an ETag or Last-Modified to check with the origin whether a stale response is still current.
Invalidation
Provide ways to stop using old versions, such as changing URLs on update, shortening lifetimes, or purging specific URLs or tags.
Derived data that can be recreated after deletion
Copies of images and HTML, API responses, and computation results that can be fetched or calculated again from authoritative data.
Source data whose loss affects the business
Persist orders, member data, article drafts, billing records, and similar data in a database or file storage.
How requests result in HIT, MISS, or 304
A cache does not unconditionally return a stored copy based only on the URL. It selects candidates using the target URI, HTTP method, request headers specified by Vary, authentication and cookies, and product-specific key rules, then evaluates freshness and revalidation conditions.
Receive a request
For example, a browser requests GET /assets/app.v8.css .
Find a matching stored response
Select a candidate matching the URI, method, Vary headers, and other requirements. If none is available, it is a MISS.
Reuse a fresh response as a HIT
If its current age is less than its freshness lifetime and other requirements are met, a stored response can be used without contacting the origin.
Conditionally revalidate a stale response
If-None-Match carries the ETag; if unchanged, receive 304; if changed, receive 200 and the new body.
Store the new response and conditions
If the response is cacheable, store the body along with Cache-Control, ETag, Vary, and related information for later requests.
Reuse without validation
current_age < freshness_lifetime means the stored response can be reused directly. An intermediate cache reports the age in Age.
A request is made, but the body is not sent
A 304 is not a completely offline response. A conditional request and validation round trip still occur; only the body transfer is avoided.
| State | Meaning | Typical behavior |
|---|---|---|
| HIT | A reusable stored response was found | Return it from the browser or an intermediate cache |
| MISS | No matching response exists or it cannot be used | Fetch from upstream or the origin |
| STALE | The freshness lifetime has expired | Normally revalidate; configuration may permit limited use of stale responses |
| 304 | The stored representation is unchanged | Reuse the stored body without retransmitting it |
| BYPASS | The response is excluded from caching or reuse despite passing through a cache | Forward to the origin due to authentication, cookies, rules, explicit settings, or similar conditions |
CF-Cache-Status、X-Cache. Even when the standard Cache-Status is present, check the implementation documentation for value meanings and when it is emitted.Benefits of caching and the risks of poor design
Caching does more than improve speed. It can reduce origin requests, data transfer, database queries, and dynamic generation, affecting reliability and operating costs. The same settings, however, create both benefits and risks.
Four effects of reuse
- Reduce latency by serving content closer to users
- Reduce application processing and database queries
- Reduce repeated transfers of the same body
stale-if-errorcan be designed to provide limited fallback responses during outages
Four failures to prevent before optimizing speed
- Prices, inventory, or articles remain stale after an update
- Sharing personalized pages leaks information
- Different languages or encodings are served under the same key
- A full purge causes a surge of misses and overloads the origin
Classify web caches by location and scope
Even one page may pass through multiple caches in the browser, CDN, reverse proxy, CMS, application, and around the database. Saying only that you cleared the cache is insufficient: identify the layer you changed.
| Type | Location and scope | Suitable content | Main considerations |
|---|---|---|---|
| Browser HTTP cache | Inside a user's browser, normally for that device and profile | Images, CSS, JavaScript, and revalidatable HTML | Retention differs by user; a hard reload does not clear the CDN |
| CDN and shared caches | Delivery points and proxies in front of multiple users | Public images, versioned static files, and shareable HTML and APIs | Watch for personalized responses, incomplete keys, edge differences, and purge scope |
| Reverse proxy | Nginx, Varnish, and similar services in front of the origin | Expensive-to-generate public HTML and APIs | Decide how authentication cookies, language, device differences, and queries enter the key |
| CMS and page cache | WordPress or another CMS stores generated HTML | Operations that return the same public page for the same input | Connect drafts, scheduled publication, permission-based views, and update events to invalidation |
| Application and object cache | Application memory, Redis, and similar stores | Configuration, aggregates, API results, and database query results | Manage invalidation when dependencies change, concurrent generation, and memory limits |
| Cache Storage | Managed in the browser by JavaScript or a service worker | Offline support, application shells, and custom fetch strategies | Separate from the HTTP cache; update and delete in code rather than relying on automatic updates or expiration |
Private cache
A cache for one user, such as a browser cache. It can handle more response types than a shared cache, but sensitive information still requires careful controls.
Shared cache
A CDN or shared proxy reuses responses across users. Limit it to public responses and separate user-specific variations through keys or by prohibiting storage.
bfcache and service workers
The back-forward cache (bfcache) and Cache Storage are distinct from the HTTP cache. Keep them separate when investigating.
Key headers for controlling and observing HTTP caching
HTTP uses several headers to express whether a response can be stored, its sharing scope and freshness, revalidation, representation differences, current age, and how caches handled it. First decide whether the response is public, varies by user, can use a changed URL, and how many minutes of staleness are acceptable; then choose values.
| Header | Role | What to check |
|---|---|---|
Cache-Control | Directs storage, freshness, sharing, stale use, and more | Choose values by response type |
ETag | A validator identifying a representation version | If-None-Match can yield 304 if it matches |
Last-Modified | Last modification time of the representation | If-Modified-Since enables conditional retrieval |
Vary | Specifies request headers that change the response for the same URL | Accept-Encoding, Accept-Language, and others; too many variations can reduce hits |
Age | Approximate seconds elapsed since the response was generated | Check response age at a shared cache; it is not simply a timer since receipt |
Cache-Status | A standard header describing how caches handled the request | Includes hit, fwd, ttl, and similar fields; not all products always emit it |
Expires | A legacy mechanism specifying expiration as an absolute time | Cache-Control max-age normally takes precedence when present |
Common Cache-Control directives
| Value | Meaning | Typical use |
|---|---|---|
max-age=seconds | Seconds a response can be considered fresh after generation | Freshness for caches including browsers |
s-maxage=seconds | Specifies freshness for shared caches | Use different TTLs for browsers and CDNs |
public | Explicitly permits storage by shared caches | Public static files and shareable public responses |
private | Prohibits storage in shared caches and limits it to private caches | User-specific pages and personalized responses |
no-cache | Permits storage but requires validation before reuse | Updated HTML and responses whose freshness must always be checked |
no-store | Requests that the response not be stored | Highly sensitive responses that should not remain in any cache |
must-revalidate | Once stale, do not reuse without successful validation | Responses where stale data could cause inconsistencies |
immutable | Indicates that the content will not change while fresh | Static files with content hashes or versions in their URLs |
stale-while-revalidate=seconds | Allows a stale response to be served while revalidating for the specified time | Public content that tolerates some delay and benefits from reduced response waits |
stale-if-error=seconds | Allows a stale response to be used for the specified time during an upstream error | Providing public information for a limited period during an outage |
no-cache does not prohibit storage
It requires validation with the origin before reusing a stored response. With an ETag, a 304 can avoid transferring the body when unchanged.
no-store prevents storage
It asks caches not to store the new response. Adding no-store later, however, does not command caches to delete all older responses stored for the same URL.
Cache-Status can describe how multiple caches handled a response in a standard format. RFC 9213 also defines a framework for targeted Cache-Control fields such as CDN-Cache-Control. Check the CDN or proxy's official documentation for actual support and precedence.Cache-Control examples by use case
These examples are starting points. Instead of applying the same values everywhere, adjust them based on whether the URL can change, how long stale content is acceptable, whether personal data is included, and whether browsers or CDNs should reuse the response.
1. CSS, JavaScript, and images with content hashes
Suitable for long-term storageapp.8d7c31.css are static files whose URLs change with their content and can be stored long-term provided old URLs are never overwritten.
Cache-Control: public, max-age=31536000, immutable2. HTML that changes
Suitable for revalidationFor articles or home pages that change at a fixed URL, allowing storage but validating before reuse is a straightforward approach.
Cache-Control: no-cache
ETag: "page-v42"The client can send If-None-Match: "page-v42" and, if the content is unchanged, the server can return 304. This reduces transfer compared with sending the body each time.
3. Shareable public APIs
Use a CDNFor APIs that return the same public result for the same input and can tolerate a few minutes of update delay, browser and shared-cache freshness can differ.
Cache-Control: public, max-age=30, s-maxage=300,
stale-while-revalidate=60, stale-if-error=600
Vary: Accept-Encoding4. Sensitive user-specific pages
Avoid storageAvoid storage for responses that should not remain in any cache, such as immediately after payment, medical or financial data, or one-time information.
Cache-Control: private, no-storeDo not mechanically add no-store to every logged-in page. Assess sensitivity, the back-navigation experience, and whether revalidation is sufficient for each case.
What happens when a cache is cleared? Methods by layer and safe updates
After a cache is cleared, the next request cannot use the stored result and must refetch, recalculate, or regenerate it. With an appropriate design, original orders, member records, articles, and source images are not deleted. However, selecting cookies or site data in the browser's clearing dialog may affect login state or locally stored information.
| Layer | Main clearing and update methods | What happens next |
|---|---|---|
| Browser HTTP cache | Browser settings, DevTools Clear browser cache, or a hard reload | Files are fetched again, so the first load takes more data and time |
| CDN | Purge by URL, prefix, tag, host, or all entries through an API or console | The next request is a MISS, increasing origin load |
| CMS page cache | Article update event, plugin function, or targeted URL invalidation | HTML is regenerated on the next request |
| Redis and application caches | Delete specific keys, use tags or generation numbers, TTLs, or event integration | Database queries or computations run again |
| Cache Storage | Service worker update logic, CacheStorage API, or DevTools | Refetch and store according to the fetch strategy defined in code |
Five ways to apply updates quickly and safely
Include a version in static-file URLs
app.css should not be overwritten; use app.8d7c31.css when content changes.
Choose HTML and API TTLs based on acceptable propagation time
Do not assume 24 hours just because content updates daily; work backward from how many minutes the old version may remain after publication.
Enable revalidation with an ETag or similar validator
Return 304 if unchanged or a new 200 response if changed, balancing transfer volume and freshness.
Prefer purging specific URLs or tags
Keep full purges as a last resort; invalidate only updated pages and dependent assets.
Prepare for concentrated misses
When a full purge or simultaneous expirations are possible, prepare warmup, request coalescing, origin capacity, and rollback.
How to check whether caching works
For stale displays, misses, or differences after login, first identify the layer and record actual response headers. Do not judge from browser appearance alone; check the same URL multiple times under different conditions.
Check with Chrome DevTools
- Open Network in DevTools and load the target page.
- Select the request and check Headers for Cache-Control, Age, ETag, Vary, Cache-Status, and product-specific headers.
- Size and transfer information may show memory cache or disk cache, and Status may show 304.
- To simulate a first-time user, enable Disable cache. This primarily removes the browser cache's effect; it does not purge the CDN.
- Vary login state, language, query, cookies, and device conditions to check whether different responses are being mixed under one key.
Record response headers with curl
# Fetch response headers only
curl -I https://example.com/assets/app.v8.css
# Request revalidation and compare the result
curl -I -H 'Cache-Control: no-cache' https://example.com/
# Send a conditional request using an ETag
curl -I -H 'If-None-Match: "page-v42"' https://example.com/Request-side Cache-Control: no-cache does not command deletion of stored responses. It requests revalidation by caches along the path, and behavior varies with CDN and browser implementation and configuration.
| Item | What it reveals | Considerations |
|---|---|---|
Cache-Control | Storage scope, freshness, revalidation, and stale use | Check whether the CDN overrides it with its own configuration |
Age | Response age in a shared cache | A missing value alone does not prove the response was not cached |
ETag / 304 | Whether conditional revalidation works | Check weak ETags, compression differences, and generation differences across servers |
Vary | Which request headers distinguish representations | Vary: * and high-cardinality values can make reuse difficult |
Cache-Status | Hit status, forwarding reason, remaining TTL, storage, and more | Output is optional; some implementations hide details for security |
| Product-specific headers | CDN- or proxy-specific HIT, MISS, and BYPASS reasons | Use the product documentation for names and meanings |
Caching, SEO, and Core Web Vitals
Simply enabling caching does not guarantee a higher search ranking. Appropriate browser, CDN, and server caches can nevertheless reduce server response work and resource transfers, providing a foundation for a better experience.
Cache versioned static assets long-term
Reduce CSS, JavaScript, and image transfers on repeat visits and serve from the origin or a nearby CDN edge. Cache expensive public HTML within the scope that can safely be shared.
Do not retain stale HTML for too long
Even after updating titles, content, prices, structured data, and canonical tags, stale HTML serves old information to users and crawlers. Design HTML revalidation or short TTLs and purges.
Common cache design mistakes and a pre-launch checklist
no-cache is mistakenly assumed to prohibit storage
no-store prohibits storage; no-cache requires validation before reuse.
Overwriting content at a long-TTL URL
Change the URL when the content of a long-cached static file changes.
Storing personalized responses in a shared cache
Do not assume authentication cookies make it safe; explicitly design private, no-store, bypass, and cache keys.
Omitting language, compression, or device differences from the key
List conditions that change the response and include necessary Vary headers or CDN keys.
Clearing only the browser and concluding the issue persists
Check the CDN, CMS, reverse proxy, Redis, and service worker separately.
Using HIT rate as the only success metric
Also observe update propagation, correctness, errors, leaks, origin load, and response time.
Ten pre-launch checks
- Classify responses as public, user-specific, or sensitive
- List conditions that change a response at the same URL
- Add content hashes or versions to static assets
- Decide acceptable staleness for HTML and APIs
- Enable revalidation using ETag or Last-Modified
- Keep personalized responses out of shared caches
- Connect update events to purge and invalidation
- Test login state, language, queries, and device differences
- Plan for origin load after a full purge
- Have bypass and rollback procedures for incidents
Frequently asked questions about caching
Simply put, what is a cache?
It stores previously fetched or computed results for reuse in later operations under the same conditions. On the web, browsers and CDNs store HTTP responses to reduce transfers and server work.
Does clearing a cache delete the original data?
Not with an appropriate design. Cached data is derived and can be fetched or regenerated from authoritative data in a database or files. Clearing cookies or site data at the same time, however, can affect login state and other local information.
Does Cache-Control: no-cache prohibit storage?
No. no-cache requires a stored response to be validated before reuse. The directive that prohibits storage is no-store.
Does 304 Not Modified mean no network request was made?
No. A conditional request and validation still take place. The server determined that the content was unchanged, so the stored body is reused without retransmission.
Does a hard reload also clear the CDN cache?
Usually not. A hard reload primarily changes how the browser fetches resources. To remove a stored CDN response, purge it through the CDN console or API.
Should a page updated daily use max-age=86400?
A response cached just before an update may remain available long afterward. Choose TTL based on acceptable staleness, revalidation, versioned URLs, and purging, not just update frequency.
Will content never be cached without Cache-Control?
Not necessarily. Without explicit freshness information, a cache may infer freshness from the last modification time or other information. Set an explicit policy for each response type to communicate your intent.
Is a higher cache HIT rate always better?
HIT rate alone is insufficient. Serving stale prices or another user's response at a high HIT rate is still a failure. Assess correctness, leak prevention, update delay, origin load, and response time together.
Standards and official sources reviewed
We prioritized standards for HTTP cache semantics and control, and checked browser, CDN, and search implementation and verification against official documentation. CDNs, CMSs, and reverse proxies can have their own rules, so also consult your product documentation in production.
- RFC 9111 — HTTP Caching
- RFC 9110 — HTTP Semantics
- RFC 9211 — The Cache-Status HTTP Response Header Field
- RFC 9213 — Targeted HTTP Cache Control
- RFC 8246 — HTTP Immutable Responses
- RFC 5861 — stale-while-revalidate / stale-if-error
- MDN Web Docs — HTTP caching
- MDN Web Docs — Cache-Control
- MDN Web Docs — Cache API
- Chrome for Developers — Network features reference
- Cloudflare Docs — Purge cache
- Google Search Central — Core Web Vitals
Fact-checked July 29, 2026. Where standards and implementation documentation differ, we distinguish specification semantics from product-specific behavior.
Define reuse conditions and updates before choosing a cache location
A cache stores past responses or computations for reuse when later operations meet the conditions. Browsers, CDNs, reverse proxies, CMSs, and applications differ in sharing scope, keys, clearing methods, and observability.
Store static files long-term using versioned URLs, design freshness and revalidation for changing HTML and APIs, and do not share personalized responses. Targeted purges, preparation for concentrated misses, testing login and language variants and immediately after publication, and rollback procedures help balance speed and correctness.