Skip to content

Page cache

Shane Rounce edited this page Nov 30, 2026 · 5 revisions

Page cache

The page cache stores the finished HTML of a page in Redis and replays it to the next visitor.

It needs WordPress 6.9 or later and WP_CACHE set to true.

What is cached

A response is stored when all of these are true:

  • it is a GET request for a front-end page;
  • the visitor is a guest (or belongs to a group covered by the logged-in page cache);
  • the response is a 200;
  • the page is not a search result, a feed or a 404;
  • the main content of the page holds real text.

Desktop and mobile visitors get separate copies, as do http and https.

What is never cached

Never cached Why
wp-admin, wp-login.php, xmlrpc.php, wp-cron.php Not pages
REST API and AJAX requests They carry their own cache rules
POST and other non-GET requests They change things
Password-protected posts Private
Responses marked private, no-store or no-cache The page said so
Pages that define DONOTCACHEPAGE The page said so. A copy stored earlier is dropped.
Previews, Customizer changesets and editor requests with ?context=edit Edits need the current content. These requests bypass the cache before and after WordPress loads.
WooCommerce basket, checkout and account pages, and anyone with a basket See WooCommerce
Requests with ?aceredis_nocache=1 Your own bypass switch
Sitemaps, if Exclude Sitemaps is on Your choice
URLs matched by the aceredis_cache_excluded_urls filter Your choice

Pages the plugin refuses to store

A page can be eligible and still not be stored. The plugin checks what was rendered before keeping it, so a broken render never replaces a good one. The reason is sent in the response header:

X-AceRedisCache: MISS; reason=empty_main
Reason Meaning
first_view The post was saved a moment ago, or the site has asked for pages to be stored on their second view with the aceredis_enable_first_pass_skip filter
protected_post The post needs a password or is not published
empty_body Nothing was rendered
is_404, status_not_200 Not a successful page
is_search, is_feed Not stored by design
empty_main The main content did not render
host_mismatch, ip_host The request came in on an address that is not the site's own
local_dev_asset_reference The page links to assets on a local development address

The empty_main check looks for the page's <main> element, then falls back to <body>. A short main area that holds real content (a heading, a paragraph, a list) counts as a rendered page, so a new site on a default theme gets its home page cached; an empty one is refused. The two thresholds are the aceredis_min_main_text_bytes (400) and aceredis_min_structured_text_bytes (40) filters. You can add checks of your own with aceredis_page_store_block_reason.

The full list of reasons, including why the cache was bypassed altogether, is on Response headers.

Query strings

Tracking parameters never split the cache. These are dropped from the key, so a campaign link is served the same copy as the clean URL: utm_*, gclid, gclsrc, gbraid, wbraid, gad_source, gad_campaignid, dclid, srsltid, fbclid, msclkid, twclid, ttclid, igshid, li_fat_id, epik, yclid, hsa_*, _hsenc, _hsmi, _kx, mc_cid, mc_eid, _ga, _gl, ref, via and v.

Other parameters are sorted and kept, so ?page=2&sort=price and ?sort=price&page=2 share a copy. Each path keeps up to 256 query variants; past that, further variants are served live.

Lifetimes

Setting Default Meaning
Page Cache TTL 3600 s How long a stored page counts as fresh
Grace window 3600 s How long past that a stale copy may still be served while a new one is made
TTL jitter off Cuts each page's fresh lifetime by a random amount, so pages warmed together do not all expire together
Page Cache Max TTL off Caps fresh lifetime plus grace in Redis

The aceredis_page_ttl and aceredis_page_grace filters set lifetimes per URL.

Stale-while-revalidate

When a page passes its fresh lifetime but is inside the grace window, the visitor still gets the stored copy at once, and a refresh is queued. One refresher re-renders queued pages in the background. The same happens after a soft purge: every page is marked stale, none is deleted, and nobody waits on a cold render.

This is the difference between a purge that costs nothing and one that sends every visitor and crawler to PHP at the same moment. See Purging and refresh.

Early serve

Normally WordPress loads, the plugin finds the stored page and sends it. That is fast, but WordPress has still booted.

With early serve, advanced-cache.php answers the request itself, before WordPress loads:

define( 'ACEREDIS_EARLY_SERVE', true );

Until that constant is set the drop-in runs in dark launch: it does everything except send the page, and reports the result in a header.

X-Ace-Early: HIT; dark-launch

Watch that header on your own pages first. When it says HIT where you expect it to, set the constant. After that a hit looks like this:

X-Ace-Early: HIT
X-AceRedisCache: HIT (advcache)

The drop-in stands aside, and lets WordPress handle the request, for anything that might not be a guest page view: any WordPress login, password or comment author cookie, any WooCommerce basket or session cookie, basket and account paths, REST requests, and non-GET methods.

X-Ace-Early Meaning
HIT Served a fresh stored page
HIT stale Served a stale stored page and queued its refresh
HIT ... filled Served a page and pasted in its live blocks from their microcache copies
MISS no-connection Could not reach Redis with the constants in wp-config.php
MISS no-tokens Connected, but the plugin has not published this site's key details there. Usually the wrong database or host.
MISS no-key No stored copy of this page
MISS dynamic The page has live blocks without a usable copy, so WordPress renders them
MISS undecodable, MISS uninspectable The stored copy could not be read here. WordPress serves the page.
BYPASS path, BYPASS crawler A path or crawler rule sent the request to WordPress

Live blocks

Some blocks must not be frozen into a cached page: a live score, a countdown, a personal greeting. List them under Exclusions > Block Exclusions and tick Treat excluded blocks as dynamic. Patterns take wildcards, for example my-plugin/live-*.

A block can also be kept live from code alone, with the aceredis_dynamic_block_patterns filter.

Those blocks are cut out of the stored page and a placeholder left in their place. On each hit the rest of the page comes from the cache and only those blocks are rendered.

Dynamic Microcache keeps each live block's HTML for a few seconds (1 to 60, default 10), which evens out the load when many visitors arrive at once.

With early serve on, a page whose live blocks all have a microcache copy is served before WordPress boots, with the copies pasted in. When a copy has just expired, an older copy (kept for twenty times the microcache TTL, at least five minutes and at most an hour; aceredis_dynamic_stale_ttl) is used and the block is rendered again in the background, at most once per block every 20 seconds. That background render needs PHP-FPM and curl. If a CDN or firewall would block the site calling itself by its public name, point it at the web server directly:

define( 'ACEREDIS_EARLY_REFRESH_ADDR', '127.0.0.1' );

Minification and compression

Both are off by default.

  • Minification minifies the HTML before it is stored. A page is stored once, as its minified copy. Content Exclusions lists text that, when found in a page, stops that page being minified.
  • Compression stores pages compressed with Brotli or gzip. You choose the method; one that PHP lacks is greyed out. A freshly rendered page is not compressed by the plugin; that is left to your web server.

Browser cache headers

Off by default. When on, page cache hits send Cache-Control: public with the max-age you set, Expires and Vary: Cookie, so browsers and proxies may reuse the page. Leave it off if you are unsure: a page in a visitor's browser cannot be purged.

Conditional requests

Each hit carries an ETag. A browser or crawler that already holds that copy and says so gets 304 Not Modified with no body, which saves the transfer as well as the render. See Response headers.

Custom routes

The page cache starts when WordPress picks a template. A route that prints its output and exits earlier is never stored. To opt in, call this before printing anything:

do_action( 'aceredis_start_page_cache' );

Changing the HTML of every page

Code that rewrites the page's HTML must do it on WordPress's own response filter:

add_filter( 'wp_template_enhancement_output_buffer', 'my_rewrite', 5 );

An output buffer of your own, started on template_redirect or template_include, wraps the page after it has been stored. The first view looks right and every cache hit loses the change.

Compression negotiation

From 0.12.0, the early drop-in and WordPress both check whether the browser accepts the stored encoding. ARC respects a quality value of zero for gzip or Brotli, validates compressed content before serving it and preserves other response fields already named in Vary. Refresh your version-controlled page-cache drop-in when updating to this release.

Compression control on the Caching tab

Clone this wiki locally