Page cache · 30 November 2026

Cache the page, not the visitor: what is safe in a WordPress page cache

A page cache hands one person's page to everybody who asks next. If that page had anything personal or time-bound baked into it, everybody gets that too. Here are the two leaks to look for and a test that finds them.

By Shane Rounce · 5 minute read

The problem: the first visitor decides what everyone sees

A page cache stores the finished HTML of a page and gives it to the next visitor without running WordPress. That is the whole point, and it is also the risk. Whatever PHP wrote into that HTML for the first visitor is now what every later visitor receives.

Most of the time that is fine, because most of a page is the same for everyone. The trouble starts with the parts that are not. I have found only two kinds, and almost every caching fault I am asked to look at is one of them.

Leak one: something about the visitor is in the HTML

Think about everything a busy site knows about a visitor: whether they are signed in, a colour scheme, a preferred format for prices or dates, a font size, what is in their basket, a greeting with their name in it.

If PHP renders any of that into the page, the first visitor's choice is stored. One person picks the dark scheme, and the next thousand get the dark scheme.

The fix is a rule, not a setting. The server always renders the neutral page: signed out, default scheme, default formats, empty basket. Each preference is then applied in the visitor's own browser, from their own stored settings.

  • Keep preferences in the browser (local storage or a cookie that PHP does not read for rendering).
  • Apply them with a small script in the <head> that sets classes on the root element before the first paint, so nobody sees a flash of the wrong version.
  • Render values such as prices or times in the site's default format and convert them on the device.
  • Fetch anything truly personal, such as a basket count, after the page has loaded.

Leak two: something about the time is in the HTML

The second leak is quieter. A page says "today's fixtures", "popular this hour" or "3 days left", and the cache keeps saying it after it has stopped being true.

The usual answer is a short lifetime, and it is not enough. A page stored one minute before midnight with an hour to live shows yesterday for most of an hour.

Put the time window into the cache key instead. A list that changes every ten minutes is stored under a name that includes the current ten minute slot:

$slot = floor( time() / 600 );
$key  = "popular:{$mode}:{$slot}";
$html = wp_cache_get( $key, 'my_lists' );

When the slot moves on, the name changes and the old entry is never asked for again. It needs no purge. It simply expires. Give it a lifetime a little longer than the slot, and never leave it without one. I have written separately about why every key needs a lifetime.

What about the parts that really must be live?

Some parts of a page change faster than the page should. A popular list, a live score, a price that moves. If the page is cached for half an hour, that part is frozen for half an hour, however clever its own cache is.

There are three honest options:

OptionWhat it costsWhen to use it
Shorten the whole page's lifetimeEvery part of the page is rebuilt more oftenThe page is cheap to build
Load the live part with JavaScriptAn extra request, and the content is not in the HTML that search engines read firstThe content does not matter for search
Re-render only that block on each hitOne small render per requestThe block's own data is already cached

Ace Redis Cache does the third with live blocks: you name the blocks that must stay current, the stored page holds a placeholder for each, and only those blocks are rendered again when the page is served. If the block caches its own output per time slot, as above, each render is one Redis read. The page cache wiki page has the settings.

What a page cache should refuse to store

A good page cache protects you from the obvious cases without being asked. ARC will not store a response for a signed-in visitor in the shared copy, a preview, a search, a feed, a password-protected post, a response marked private or no-store, or a request carrying a basket or session cookie. Each refusal is named in a response header, which I cover in how to read your cache's headers.

Those guards catch what WordPress knows about. They cannot know that your theme prints a visitor's first name in the header. That part is yours to check.

The two browser test

This is the test I run before I trust any page cache, and it takes five minutes.

  1. Open the site in a normal window. Sign in if the site allows it, change every preference you can find and put something in the basket.
  2. Load a handful of pages, including the home page and one article or product.
  3. Open a private window, which shares nothing with the first, and load the same pages.
  4. Look for anything from the first visit: a name, a scheme, a basket count, a "welcome back".
  5. Repeat the other way round: load pages in the private window first, then in the signed-in one.

Checklist

  • List every piece of per-visitor state on the site. None of it should be rendered by PHP into a cacheable page.
  • Apply preferences in the browser before the first paint.
  • Put time windows into cache keys instead of trusting a short lifetime.
  • Keep the few live parts live, and cache everything else.
  • Test with two browsers that share nothing.

If you are not sure which layer is doing what, start with page cache and object cache, then see how ARC decides what to serve.

All notes Get the latest release