From 982abe28b6440d9b438866b6ce2021242be40d49 Mon Sep 17 00:00:00 2001 From: Altis Assistant Date: Tue, 16 Jun 2026 15:47:36 +0000 Subject: [PATCH] docs: clarify WordPress 404 page caching (cherry picked from commit 4d490729e4afd7cd6526488105153f1d8f2ba832) --- docs/page-caching.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/page-caching.md b/docs/page-caching.md index 4057fda1..11dc4fe1 100644 --- a/docs/page-caching.md +++ b/docs/page-caching.md @@ -53,9 +53,12 @@ Pages which can be cached have default time-to-live (TTL) values within the cach - Success responses (`200`): 300 seconds (5 minutes) - Client errors (`400`, except `404`): 10 seconds -- Not found errors (`404`): 300 seconds (5 minutes) +- Not found errors (`404`) generated by nginx before the request reaches WordPress: 300 seconds (5 minutes) - Server errors (`5XX`): 300 seconds (5 minutes) +WordPress-generated 404 responses are not cached by default. WordPress sends `no-cache` headers for these responses, and Altis does +not cache responses with a `Cache-Control: no-cache` header. + Time-to-live values should be balanced between achieving high cache hit rates and ensuring fresh content is served. This can be adjusted by sending @@ -68,6 +71,20 @@ For example, to specify a lifetime of one hour for a specific page: header( 'Cache-Control: max-age=' . HOUR_IN_SECONDS ); ``` +For high-traffic 404 pages generated by WordPress, you can override WordPress' default `no-cache` headers and allow the CDN to cache +the response by sending an explicit `Cache-Control` header: + +```php +add_action( 'template_redirect', function () { + if ( ! is_404() ) { + return; + } + + $lifetime = 5 * MINUTE_IN_SECONDS; + header( 'Cache-Control: s-maxage=' . $lifetime . ', max-age=' . $lifetime . ', must-revalidate' ); +} ); +``` + (Note that headers should be sent before any output occurs on the page.) ## Developer Considerations