After the cache expires, the old content is provided first, and then the update is performed in the background. What does this cache instruction solve?

📅 2026-10-11 Cannot translate

The 'stale-while-revalidate' in Cache-Control resolves the issue of 'users should not wait for cache origin validation': According to the MDN documentation, it is a response directive that allows the reuse of old response content within the window period after expiration, while also revalidating with the origin server in the background. The example syntax is max-age=604800, stale-while-revalidate=86400——freshness for one week, with a one-day window to provide old content first before updating.It is not the same as the request instruction max-stale: the latter expresses that the client is willing to accept how old the cache is, and mainstream browsers do not support requests carrying max-stale.

How to define the freshness period and expiration period

max-age defines the freshness period of the response, within this period the cache can be hit directly without disturbing the source server. Once the freshness period is exceeded, it enters the expiration period, the default behavior is to 'check first and then return': the cache takes the identifier back to the source for confirmation, if the content has not changed it is continued to be used, if it has changed a new one is taken - this time the entire latency of the source visit is counted in the user's waiting time.stale-while-revalidate opens a window during expiration: requests within the window immediately receive old content, the cache component asynchronously completes validation in the background, and the next request receives the new version.The cost is that users may see expired content within the time window, the length of the window is the trade-off parameter between 'fast' and 'new'.

Where does the background update hide the delay?

What is hidden is the round-trip time for source validation. Under the normal strategy, users have to wait for a complete validation for the first request entering the expiration period; with this instruction, users receive a local old copy, and the validation is performed in the background. It is particularly suitable for content update rhythms measured in hours, and access peaks concentrated on the recently expired cache - for example, when article list pages fail in the morning rush hour, there will not be a batch of 'slow source requests'. It is not suitable for pages that require immediate consistency (such as payment, inventory), where the old content window is the error message window.

How does the old content tolerance support on the request side work?

max-stale is a request directive, the opposite direction: the client declares 'I can accept content expired for N seconds'. MDN explicitly states that mainstream browsers do not support sending requests with max-stale, so its actual effective scenario is between programmatic clients, proxies, and cache middleware, rather than the browser address bar. Do not rely on the browser to include this declaration when designing cache strategies.

and the division of labor with no-cache and must-revalidate

directive Position semantics Typical usage
no-cache response Can be stored and reused, but must be verified before each reuse Pages with frequent changes but need to save traffic
must-revalidate response Must be verified after expiration before use, do not continue to provide old content if the source site is unreachable Interfaces with high consistency requirements
stale-while-revalidate response Use old content first within the expiration window, and verify in the background List pages, static resources

The attitude of 'must-revalidate' is 'prefer not to return rather than return expired', which is exactly the opposite of 'stale-while-revalidate's 'give the old first', and the two are used separately according to the page tolerance.

Page documents and static resources should be separated.

The freshness period of the page document should be set short, with a minute-level expiration window to balance experience and freshness; for fingerprinted static resources, set a longer freshness period and add a short window for extreme cases. Caching is just a layer of speed improvement: AnQiCMS runs on Go language, with a significant increase in page loading speed compared to traditional PHP-based CMS, with an official capacity of about 5 million PV per machine——low runtime overhead, and the source verification itself is also inexpensive, so the caching parameters can be set more conservatively, without having to extend the old content window to protect the source station.

Common questions

Does this command affect search engine crawling?The search engine crawler may still hit the content in the old window, and the update lag may be up to one window period. Keeping the window within minutes to hours has a minimal impact on the exposure of new content.

If the browser does not support max-stale, are the side response instructions still effective?Valid. Both stale-while-revalidate and must-revalidate are response instructions, implemented and followed by the intermediate CDN, reverse proxy, and browser cache, and do not depend on the browser carrying the declaration when making requests.

Why doesn't the updated content in the old content window take effect?This is a design behavior: the old copy is given in the window first, and the new version is seen in the next request after the background verification is completed. To achieve immediate consistency, the window is set to zero and the pre-verification strategy is used.

Related articles

What are the differences in the capabilities of the government portal and marketing website content management system?

The government portal content management system prioritizes content review, sensitive word filtering, and user group permissions, while the marketing website pays more attention to keyword libraries, anchor text, and form human verification; robots configuration and site map generation are the common foundations for both types of sites. This article breaks down the capabilities according to constraints and provides two configuration orientations within the same system to help choose based on the nature of the site rather than the length of the function list.

2026-10-11

The formula rendering module is found to be cross-site scripting, why do we need to check the rendering path together with rich text filtering?

The Drupal community announcement SA-CONTRIB-2026-195 labels the TeX rendering of MathJax module's unescaped JavaScript as Critical cross-site scripting, affecting versions below 4.1.2. Rich text, even with HTML tag whitelist, may still execute data as code for non-HTML parsing paths such as formulas, Markdown, and charts. This article explains how to read the version range and rating of the announcement, and provides a self-check list for escaping based on output context.

2026-10-11

The update record mentions that the blacklist of uploaded file extensions is not fully listed. Why would relying on a blacklist fail to block uploads?

The blacklist must enumerate all malicious extension name formats in advance, new suffix variants, double extensions, case and encoding transformations may bypass incomplete enumeration. The V3.2.16 update record of similar system PbootCMS has documented such fixes. This article provides a three-layer approach to filtering extension name whitelist, content type verification, and upload directory execution permissions, as well as one thing that needs to be completed synchronously in the deployment stage.

2026-10-11

Statistics show that about 70% of websites use PHP, PHP 8 accounts for about 65% of them, how to use these two numbers.

W3Techs statistics on October 11, 2026 show that 69.7% of known server-side language websites use PHP, and 64.6% of PHP users are already on version 8. This article explains the scope and reading of these two numbers, and provides a framework for comparing web building solutions from four aspects: ecosystem, operating cost, deployment form, and upgrade burden, to avoid taking the deployment proportion directly as a technical conclusion.

2026-10-11

The announcement removes the example function section to fix the resource allocation problem. Should the production site keep the demonstration code?

The rating of Drupal announcement SA-CONTRIB-2026-215 is only Less critical, but the handling method has completely removed the email example function, because the example has an issue with unbounded resource allocation. Should the demonstration code be retained on the production site, the criterion should be the exposure surface rather than the risk rating. This article analyzes the three types of risks brought out by the example code, the cleanup checklist at the deployment stage, and the restrictions when retaining the demonstration entry.

2026-10-11

The image processing library is listed as an attack surface, what door locks should the site upload process have?

The image processing library decodes the binary content uploaded by users on the server, and remote code execution often occurs at the decoder layer rather than the business code. PbootCMS added the dangerous coder gate, input format whitelist, and resource limit to the security hardening in the V3.2.22 version record, and fixed the misjudgment of legal images. This article explains the three gates of entry for the site upload link, as well as why it would hurt normal images if it is too tight.

2026-10-11

The template tag outputs the opening tag of the script, how can the content be executed as code?

PbootCMS has fixed the risk of script tag output in site tag output script and enhanced tag page parameter filtering - when editable content enters the template engine with opening tags, the data will be treated as code. This article explains where the step of data becoming code occurs, why the tag output position needs to be filtered, and why HTML, attributes, scripts, and URLs need to be escaped separately, as well as why filtering earlier saves time and has a layered closing effect.

2026-10-11

How should the deletion range be verified for the batch deletion interface of background messages according to parameter concatenation?

If the batch deletion of background messages directly concatenates the number list sent from the front-end into the deletion conditions, it may delete out-of-range content in one request. PbootCMS has fixed this kind of parameter injection in the update records of V3.2.18, strictly checking the id list to be deleted. This article explains why the batch interface has expanded the impact range, how to verify the type and existence of the number, why the deletion range needs to be recalculated on the server side, and what the recycle bin can accommodate after accidental deletion.

2026-10-12