Skip to content
Blog

What a page cache can and cannot do

What a page cache can and cannot do for a WordPress site, which pages it serves, which it skips on purpose, and when to clear it by hand.

The WP Waterfall team · Guides

A page cache is the biggest speed win a WordPress site can get, and also the most misunderstood. This post explains what a page cache can and cannot do, using the one every WP Waterfall site runs. You will know which pages it serves, which it skips on purpose, and when to clear it.

What a page cache can do

WordPress builds every page by running PHP code and asking the database. A page cache saves the finished page, so the next visitor gets the saved copy without any code running. On WP Waterfall, the web server keeps that copy for an hour unless you change the time, and the response header x-wpwaterfall-cache tells you what happened: HIT came from the cache, MISS was built and stored, and BYPASS was never cached.

curl -I https://example.com/about/ | grep -i x-wpwaterfall-cache
The cache header on a response says whether the page came from the cache or from PHP.

Two details make it more than a speed trick:

  • When a page expires, one request rebuilds it while every other visitor gets the old copy. A busy page reaches PHP once, not a hundred times.
  • If PHP fails or times out, visitors get the last good copy instead of an error page.

There is a second layer too. Cloudflare keeps copies of your pages and files at the edge, close to visitors around the world, on every plan with nothing to buy. The edge keeps a page for an hour by default, and you can set it from 30 minutes to 30 days.

What a page cache cannot do

It cannot serve a page that belongs to one person. A signed in user, a commenter, a shopper with a cart, and anyone on /wp-admin, /checkout, or /my-account always reach PHP. So does every form submission (a POST), and any response that sets a cookie. That last one matters: a plugin that sets a cookie on every page turns the cache off for everyone, and the x-wpwaterfall-cache-reason header names the cookie.

A request stops at the cache when it can, and goes on to PHP and the database when it cannot.

It cannot make slow code fast for those visitors. A membership site where everyone is signed in, or a store at checkout, needs fast PHP and a quick database. For that, the APM tool shows where the time goes, and a higher site tier gives more PHP threads.

It cannot know when a page changed unless something tells it. That is why the purge rules matter.

When does the cache clear itself?

WordPress tells the cache. When you publish or update a post, approve a comment, save a menu or widget, switch a theme, or update a plugin, the pages that changed are cleared. After a clear, WP Waterfall asks your site for the home page and the pages visitors asked for most today, so the first visitor gets a stored copy.

Tracking parameters do not make new copies. /?utm_source=x reads the plain page. Any other query string is cached as its own page, and you can add parameters to ignore under Caching, then Rules.

When should I clear it by hand?

When you changed something WordPress did not see: a CSS file replaced over SFTP with the same name, a setting a plugin keeps outside the post table, or a widget drawn from an outside feed. Open the site, then Caching, and use Clear URL cache for one page or Clear all caches for everything. Clear all caches empties the page cache, the object cache, PHP's code cache, and the edge in one go. A WordPress admin can do the same from the admin bar.

Clearing everything on a busy site costs a little: the first visit to each page runs PHP again. Clear one path when one path changed. The full list of settings is in Edge cache and CDN.

What to do next

Run the curl line above on your home page and on /checkout/ or /wp-admin/. One should say HIT and the other BYPASS. If the home page says BYPASS, read the reason header and find the cookie.

Read next

Try what you just read about.

See it in your own dashboard.