Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion docs/page-caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading