Performance

The Cookies Quietly Bypassing Your WordPress Page Cache

Which WordPress and WooCommerce cookies should bypass a page cache, with tested nginx and Varnish rules and Cloudflare and LiteSpeed notes. Checked 15 Nov 2026.

Varun DubeyVarun Dubey
·13 min read
Two panels listing WordPress and WooCommerce cookies that should skip the page cache and cookies that should keep serving cached pages

The cookies that should make a page cache skip a request are the ones that mean “this response is personal”: wordpress_logged_in_* (and wordpress_sec_* on HTTPS logins), wp-postpass_*, comment_author_*, and on a WooCommerce store woocommerce_items_in_cart, woocommerce_cart_hash and wp_woocommerce_session_*. Everything else, including wordpress_test_cookie, woocommerce_recently_viewed and consent or analytics cookies, should still get a cached page. Most “my cache hit rate is low” problems come from a wildcard rule that treats the second group like the first.

We checked every cookie name below against WordPress core and WooCommerce source on 15 Nov 2026, then ran the rules on nginx 1.30.6 and Varnish 9.1.0 in Docker to confirm what each one does. Cloudflare and LiteSpeed behaviour comes from their documentation, and we say so where we did not run it ourselves.

Which WordPress cookies should bypass a page cache?

Core defines its cookie names in wp_cookie_constants() in wp-includes/default-constants.php. Each name ends with COOKIEHASH, an md5 of the site URL, which is why the cookie on your site looks like wordpress_logged_in_3f2a.... That is also why every sound rule matches a prefix of the name and not the full string.

define( 'AUTH_COOKIE',        'wordpress_'            . COOKIEHASH );
define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_'        . COOKIEHASH );
define( 'LOGGED_IN_COOKIE',   'wordpress_logged_in_'  . COOKIEHASH );
define( 'TEST_COOKIE',        'wordpress_test_cookie' );
// Source: wp-includes/default-constants.php, checked on 15 Nov 2026

Notice that AUTH_COOKIE is just wordpress_ plus the hash. A rule written as wordpress_ matches the login cookies, the secure cookie and the test cookie alike. We come back to that trap in the nginx section, because it is the most common way a rule goes wrong.

Cookie

Set by core when

Bypass the cache?

wordpress_logged_in_*

A user logs in

Yes. This is the one signal every page cache honours.

wordpress_sec_*

A user logs in over HTTPS (admin-area auth cookie)

Yes, though it always arrives with the logged-in cookie.

wp-postpass_*

A visitor submits a password for a protected post (wp-login.php?action=postpass)

Yes. The cached copy of a locked post must never reach a visitor who has not unlocked it.

comment_author_*, comment_author_email_*, comment_author_url_*

A guest comments and ticks the “save my details” box

Yes if the comment form pre-fills their details, otherwise optional.

wp-settings-{user_id}, wp-settings-time-{user_id}

A logged-in user changes an admin UI setting

Not needed as a rule, because these only exist for logged-in users who already carry the login cookie.

wordpress_test_cookie

Anyone loads wp-login.php

No. It only checks that the browser accepts cookies.

Two details in core are worth knowing. The comment cookies are only written when the commenter ticks the cookie-consent checkbox: wp-comments-post.php reads wp-comment-cookies-consent, and wp_set_comment_cookies() clears the cookies when consent is false. So on most modern sites few visitors ever carry one. And wp_set_comment_cookies() returns early for logged-in users, so it never double-marks someone who is already bypassed.

Which WooCommerce cookies should bypass the cache?

Three cookies mean “this visitor has a cart or a session”. Two others look similar and do not. The source files are class-wc-cart-session.php, class-wc-session-handler.php, class-wc-cache-helper.php and wc-product-functions.php in the WooCommerce repository.

Cookie

Set when

Bypass?

woocommerce_items_in_cart

The cart is not empty. Value is 1, removed when the cart empties.

Yes

woocommerce_cart_hash

Same moment. Value is the hash of the cart contents.

Yes

wp_woocommerce_session_*

The session cookie is written, usually after an item is added to the cart or a customer logs in. The name is wp_woocommerce_session_ plus COOKIEHASH and can be changed by the woocommerce_cookie filter.

Yes

woocommerce_recently_viewed

Only when a product page is viewed and the Recently Viewed Products widget is active on the site

No

woocommerce_geo_hash

Only when “Default customer location” is set to “Geolocate (with page caching support)”. Lives for one hour.

No

One correction to something we used to say on this page: woocommerce_recently_viewed is not set for every product view on every store. wc_track_product_view() returns early unless the widget is active, so a site without it never creates the cookie. On a site that does use the widget, the cookie is set for every visitor who opens a product, and a rule that bypasses on it quietly uncaches your best-performing pages.

The cart and checkout pages are protected a second way. WC_Cache_Helper::prevent_caching() runs on the wp_headers filter, and for the cart, checkout and My Account pages it sends no-cache headers and defines three constants that many caching plugins respect:

wc_maybe_define_constant( 'DONOTCACHEPAGE',   true );
wc_maybe_define_constant( 'DONOTCACHEOBJECT', true );
wc_maybe_define_constant( 'DONOTCACHEDB',     true );
// Source: class-wc-cache-helper.php, set_nocache_constants(), checked on 15 Nov 2026

A server-level cache such as nginx FastCGI cache or Varnish does not read those PHP constants, which is why server rules still need the URL exclusions for /cart/, /checkout/ and /my-account/. If you maintain a plugin that renders personal output, defining DONOTCACHEPAGE yourself is a one-line courtesy to every plugin cache that honours it.

What about membership and community plugin cookies?

We deliberately do not publish a list of plugin cookie names here. We could verify the WordPress and WooCommerce names in source, and we could not do the same for every membership, LMS and community plugin, so any list we gave would be guesswork. A wrong name in a bypass rule does nothing, and a missing one serves a member another member’s page.

You can find the real names for the plugins on your own site in about two minutes. Log in as a test member, open the browser dev tools, go to Application and then Cookies, and note every cookie that was not there before you logged in. Then confirm with curl that an anonymous request carries none of them:

# Anonymous request: any Set-Cookie here is a cache-killer (checked on 15 Nov 2026)
curl -sI https://example.com/ | grep -i '^set-cookie'

# Same page with the cookie you found: does the cache layer now skip it?
curl -sI -b 'the_cookie_name=1' https://example.com/ | grep -i -E 'x-fastcgi-cache|x-cache|cf-cache-status|x-litespeed-cache'

If a plugin sets a cookie on anonymous visitors, that is a plugin problem, not a rule problem. nginx will not store a response that carries a Set-Cookie header (the nginx FastCGI module documents this), and Cloudflare documents the same for its default behaviour. One plugin that starts a session on every page can turn a whole site uncacheable without a single rule being involved.

How do I measure how many requests bypass my cache?

Do not start from a plugin dashboard. Its hit rate counts only requests the cache was allowed to handle, so a request that bypasses the cache never shows up as a miss. Count at the layer that serves the response.

On nginx, log the cache status and split it by URL. Add this to the http block, reload, wait for a representative slice of traffic, then count:

log_format cachelog '$remote_addr $status $upstream_cache_status $request_time "$request"';
access_log /var/log/nginx/cache.log cachelog;
# checked on 15 Nov 2026 against nginx 1.30.6
# Status totals, average time and seconds spent per status
awk '{ n[$3]++; t[$3]+=$4 } END { for (s in n) printf "%-8s %7d reqs  avg %.3fs  total %.0fs\n", s, n[s], t[s]/n[s], t[s] }' /var/log/nginx/cache.log

# Which URLs bypass? Cart and checkout at the top is correct. Your home page is not.
awk '$3=="BYPASS" {print $6}' /var/log/nginx/cache.log | sed 's/?.*//' | sort | uniq -c | sort -rn | head -20

The nginx documentation lists the values $upstream_cache_status can take, including BYPASS, MISS, HIT and EXPIRED. A bypass costs a full WordPress boot, while a hit is a file read, so the average time per status turns the ratio into seconds of PHP work you could remove. As a guide, a content site that shows more than a few percent BYPASS on ordinary posts has a rule that matches too much. The PHP-FPM tuning guide turns those seconds into worker counts, which is the number that decides whether visitors see queueing at your peak minute.

If you cannot read server logs, probe from outside. This script warms each URL with the cookie first, so a first-request MISS is not mistaken for a bypass, then reads whichever cache header your stack sends:

#!/usr/bin/env bash
# cachecheck.sh https://example.com/shop/   (checked on 15 Nov 2026)
URL="${1:?usage: cachecheck.sh <url>}"

probe() {
  local label="$1"; shift
  local out
  curl -sS -o /dev/null "$@" "$URL"   # warm with the same cookie
  out=$(curl -sS -o /dev/null -D - "$@" "$URL" \
        | grep -i -E '^(x-fastcgi-cache|x-cache|cf-cache-status|x-litespeed-cache):' \
        | tr -d '\r' | paste -sd' ' -)
  printf '%-18s %s\n' "$label" "${out:-no cache header}"
}

probe "anonymous"
probe "cart cookie"      -b 'woocommerce_items_in_cart=1'
probe "session cookie"   -b 'wp_woocommerce_session_x=1'
probe "logged in"        -b 'wordpress_logged_in_x=1'
probe "recently viewed"  -b 'woocommerce_recently_viewed=12|15'
probe "test cookie"      -b 'wordpress_test_cookie=WP%20Cookie%20check'

The expected result on a store is: anonymous, recently viewed and test cookie are cache hits, and cart, session and logged in are not. Any other combination is a bug. A bypass on the second group costs you cached pages. A hit on the first group means one visitor’s personal page can be served to another, which is the failure that matters.

How do I write cookie bypass rules for nginx fastcgi_cache?

Use a map on $http_cookie, so the logic sits in one place and reads clearly a year later. The two directives that act on it are fastcgi_cache_bypass, which stops a cached response being served, and fastcgi_no_cache, which stops the new response being stored. The nginx documentation says that if at least one parameter is non-empty and not 0, the bypass or no-store applies. Use both so a personal page is neither served from the cache nor saved into it.

# http block. Regex values use ~* for case-insensitive matching (ngx_http_map_module).
map $http_cookie $skip_cache {
    default 0;

    "~*wordpress_logged_in_"       1;
    "~*wordpress_sec_"             1;
    "~*wp-postpass_"               1;
    "~*comment_author_"            1;

    "~*woocommerce_items_in_cart"  1;
    "~*woocommerce_cart_hash"      1;
    "~*wp_woocommerce_session_"    1;
}

# Transactional pages, whatever cookies arrive.
map $request_uri $skip_uri {
    default 0;
    "~*^/(cart|checkout|my-account)(/|$)" 1;
}

# server block
location ~ \.php$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;

    fastcgi_cache        WPCACHE;
    fastcgi_cache_valid  200 10m;
    fastcgi_cache_bypass $skip_cache $skip_uri;
    fastcgi_no_cache     $skip_cache $skip_uri;
    add_header X-FastCGI-Cache $upstream_cache_status;
}
# checked on 15 Nov 2026: nginx -t passes on nginx 1.30.6; define WPCACHE with fastcgi_cache_path

We ran this exact map in a Docker lab (nginx 1.30.6 in front of PHP 8.3-FPM with a one-line page) and sent each cookie twice, so the second request was a fair test of the rule. Results from that run:

Request carries

X-FastCGI-Cache

no cookie

HIT

woocommerce_items_in_cart=1

BYPASS

wp_woocommerce_session_abc=1

BYPASS

wordpress_logged_in_abc=1

BYPASS

wp-postpass_abc=1

BYPASS

comment_author_abc=Ann

BYPASS

woocommerce_recently_viewed=12|15

HIT

wordpress_test_cookie=...

HIT

a consent cookie

HIT

request to /cart/

BYPASS

Now the trap. We changed two lines to the wildcard form that many copied snippets use, "~*wordpress_" and "~*woocommerce_", and ran the same probes. The page with a harmless x=1 cookie stayed a hit, but woocommerce_recently_viewed and wordpress_test_cookie both turned into BYPASS. The first is set for everyone who opens a product (when the widget is on), and the second for everyone who has ever loaded your login page. Under the wildcard rule, those visitors lose the cache on every later page view, for as long as the cookie lives.

For the full server configuration these lines slot into, including the cache path, purge-on-publish and header debugging, read our nginx FastCGI cache setup guide. If you also want pages to keep serving when PHP is down, our stale-cache walkthrough covers fastcgi_cache_use_stale and the 503 trap.

How do Cloudflare cache rules and APO treat WordPress cookies?

Cloudflare has three different behaviours, and mixing them up explains many “Cloudflare ignores my cookie rule” reports.

  • Default behaviour. Cloudflare’s documentation says the CDN does not cache HTML or JSON by default, and caches by file extension, not by content type. A WordPress page is not cached at the edge unless you add a rule or use APO. It also does not cache a response that has a Set-Cookie header, or one with Cache-Control set to private, no-store, no-cache or max-age=0.
  • Cache rules with Cache Everything. When you make HTML eligible for cache, the same documentation warns that it caches all HTML regardless of dynamic content, and suggests adding a condition such as the presence of a cookie. That condition is yours to write.
  • Automatic Platform Optimization (APO). APO needs the Cloudflare for WordPress plugin. Cloudflare publishes a fixed list of cookie prefixes that always bypass its cache under APO.

The APO list on the “Query parameters and cached responses” reference page, checked on 15 Nov 2026, is: wp-, wordpress, comment_, woocommerce_, xf_, edd_, jetpack, yith_wcwl_session_, yith_wrvp_, wpsc_, ecwid, ec_, bookly_ and bookly. These are prefixes, so by that rule a cookie that begins with woocommerce_ or wordpress bypasses APO, which would include woocommerce_recently_viewed and wordpress_test_cookie. That follows from the documented prefix rule and we did not test it on a live APO site, so treat it as a reading of the docs rather than a measurement. The practical point stands: on APO you cannot narrow the list, so the way to keep visitors cacheable is to stop those cookies being set (for example, remove the Recently Viewed widget if you do not use it) and to keep the login page away from ordinary visitors.

If you use plain cache rules and not APO, write the bypass expression with named cookies. The expression syntax below follows Cloudflare’s own “Bypass Cache on Cookie” example, which uses http.cookie contains:

(http.cookie contains "wordpress_logged_in_") or
(http.cookie contains "wp-postpass_") or
(http.cookie contains "comment_author_") or
(http.cookie contains "woocommerce_items_in_cart") or
(http.cookie contains "woocommerce_cart_hash") or
(http.cookie contains "wp_woocommerce_session_") or
(starts_with(http.request.uri.path, "/cart")) or
(starts_with(http.request.uri.path, "/checkout")) or
(starts_with(http.request.uri.path, "/my-account"))
// Set the rule action to "Bypass cache". Checked against Cloudflare docs on 15 Nov 2026

Put this rule above the one that makes HTML eligible for cache, because Cloudflare evaluates rules in order. Cloudflare notes that a rule set to bypass can show cf-cache-status: DYNAMIC rather than BYPASS, so read DYNAMIC on a cart page as correct, and the same status on an anonymous post as the symptom. Our caching layers guide explains how this edge layer fits with your plugin and host caches, and in which order to purge them.

How do I exclude cookies from the cache in LiteSpeed?

With the LiteSpeed Cache plugin, the setting is LiteSpeed Cache > Cache > Excludes > Do Not Cache Cookies. The plugin documentation describes it as a list of cookies that stop a page from being cached when one appears in the request, and adds a warning that is easy to miss: if you list a cookie that appears on every page, you exclude the whole site from the cache. Enter only the names that mean something, one per line.

Three other defaults in that documentation matter for cookies. Cache Logged-in Users is on by default, and pages are stored in a private cache by IP address and session ID, so LiteSpeed already handles logged-in visitors differently from the shared nginx and Varnish model above. Cache Commenters is on by default, which means a visitor who just commented sees the cached page without their pending comment unless you turn it off. And Cache Login Page has defaulted to off since LSCWP 7.9.

If the cache is at a layer in front of the plugin, such as a LiteSpeed Web ADC, the plugin setting alone may not be enough. In a wordpress.org support thread from January 2026, LiteSpeed support explained that on an Apache plus ADC setup, cookie-based no-cache rules have to be added at the ADC as well, and gave this rewrite form for the cart cookie:

RewriteCond %{HTTP_COOKIE} woocommerce_items_in_cart
RewriteRule .* - [E=Cache-Control:no-cache]
# From LiteSpeed support in a wordpress.org thread, checked on 15 Nov 2026. We did not run LiteSpeed for this refresh.

How do I handle cookies in Varnish?

Varnish starts from the opposite default. The Varnish documentation notes that the built-in vcl_recv prevents caching when a client sends a cookie. So with no VCL at all, every request from a visitor with any cookie, including a consent cookie, goes to PHP. The fix has two parts: send the personal requests to the backend deliberately, and remove the Cookie header from everyone else so they share one cached copy.

vcl 4.1;

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

sub vcl_recv {
    # Personal requests: never serve or store them.
    if (req.http.Cookie ~ "(^|;\s*)(wordpress_logged_in_|wordpress_sec_|wp-postpass_|comment_author_|woocommerce_items_in_cart|woocommerce_cart_hash|wp_woocommerce_session_)") {
        return (pass);
    }
    if (req.url ~ "^/(cart|checkout|my-account)(/|\?|$)") {
        return (pass);
    }

    # Everyone else shares one cached copy, so drop the Cookie header.
    unset req.http.Cookie;
}
// checked on 15 Nov 2026: loads and serves on Varnish 9.1.0 (Docker)

We ran this in front of the same lab backend. Anonymous requests, woocommerce_recently_viewed and wordpress_test_cookie came back from cache (with a small vcl_deliver that sets X-Cache to HIT when obj.hits is above zero). The cart cookie, session cookie, logged-in cookie, comment cookie and the /cart/ URL all came back as MISS, which is what a pass looks like. Two things to know before you copy it. Stripping the Cookie header means PHP never sees the cookie on anonymous requests, so anything server-side that reads a harmless cookie (a server-rendered consent banner, say) will stop seeing it, while JavaScript-read cookies are unaffected. And the anchor (^|;\s*) matters, because it makes the pattern match the start of a cookie name and not text inside another cookie’s value.

Which cookie rules does each cache layer need?

Layer

Default for a request with a cookie

Where you set the bypass

How we checked

nginx fastcgi_cache

Cached unless a bypass variable is non-empty

map $http_cookie with fastcgi_cache_bypass and fastcgi_no_cache

Run in Docker, nginx 1.30.6

Varnish

Not cached (built-in vcl_recv)

Your vcl_recv: pass on named cookies, unset Cookie for the rest

Run in Docker, Varnish 9.1.0

Cloudflare cache rules

HTML not cached at all until a rule makes it eligible

A Bypass cache rule using http.cookie contains, placed first

Cloudflare documentation

Cloudflare APO

Fixed prefix list always bypasses

Cannot edit the list

Cloudflare documentation

LiteSpeed Cache plugin

Cached, logged-in users in private cache

Do Not Cache Cookies setting

LiteSpeed documentation and support thread

Common mistakes people report

These are recurring problems from support threads and issue trackers, paraphrased, with the thread date so you can judge how current each one is. Checked on 15 Nov 2026. Where a thread is old, we say so; the behaviour it describes is still visible in current source.

  • Reading the exclusion list backwards. A WP-Optimize user wanted to “not cache” woocommerce_cart_hash and was unsure which box to use. Support’s answer was that the cookie list means “if this cookie is present, do not cache the page”, which is what you want for a cart. The same wording confuses people in several plugins. Source: WP-Optimize support thread, about three years old.
  • Expecting a cached page for someone with a cart. A Super Page Cache user asked how to serve cached pages while woocommerce_items_in_cart is present. The plugin contributor replied that this is not possible, because any custom cookie like that makes the plugin bypass the cache. That is by design: a shopper with items in the cart should see their cart. Source: Super Page Cache support thread, almost five years old.
  • Stripping cookies to force cache hits, then breaking the cart. Another user on the same plugin enabled the option to strip cookies so pages would cache, and then could not add anything to the cart. Removing the cookie removes the signal that tells the cache a request is personal. Source: Super Page Cache support thread, nearly three years old.
  • A stale mini cart after adding the cookie to an exclusion list. A LiteSpeed Cache user listed woocommerce_items_in_cart as an excluded cookie and the mini cart still showed an empty cart. LiteSpeed support traced it to an extra cache layer in front of the plugin, where the cookie rule also had to be added. Source: LiteSpeed Cache support thread, about ten months old.
  • Geolocation with page caching filling the cache with unique URLs. A WP Super Cache user reported the cache filling with URLs ending in ?v= plus a hash, so each page was effectively unique, and a currency switcher stopped working. The option works by a 307 redirect that adds the hash, which we confirmed in class-wc-cache-helper.php, so the trade-off remains. Source: WooCommerce issue 9122, opened in 2015 and now closed.
  • Wildcard cookie rules. We did not find a single canonical thread for this one, so we are reporting our own reproduction instead: in our nginx lab, woocommerce_ and wordpress_ wildcards turned the recently viewed and test cookies into permanent bypasses (see the nginx section above).

What if most of my traffic is logged in?

Everything above assumes anonymous visitors are the majority. On a membership site, a community or an LMS, they are not. Members carry the logged-in cookie, which is correct to bypass on, and no amount of rule tuning changes that. The page cache is the wrong tool for that traffic, so treat the logged-in side as its own performance problem.

Start with a persistent object cache, because logged-in requests still run WordPress and the saving is in making that run cheaper. Our notes on running an object cache at scale cover the failure modes. After that, cache the expensive shared fragments (an activity feed’s markup, a directory listing) in a transient keyed by the query and not the user. Per-role page caching exists in some tools and is only safe when every member of that role sees identical output, so test it by logging in as two members and diffing the HTML. Last, do less per request: fewer autoloaded options and no per-row queries in loops.

Frequently asked questions

Should I cache pages for logged-in users?

Only if you can show the output is identical for everyone in that group and your cache keys on role or user. The failure mode is one member seeing another member’s page, which is far worse than a slow page. LiteSpeed’s private cache per IP and session is built for exactly this, which is why it is on by default there and absent from the shared nginx and Varnish setups above.

Is it safe to bypass on wordpress_ as a prefix?

It is safe in the sense that it never serves a personal page, and wasteful because the prefix also matches wordpress_test_cookie, which core sets for anyone who loads wp-login.php. Name the cookies you mean: wordpress_logged_in_ and, if you want it, wordpress_sec_.

My host manages caching. Is this my problem?

The rules are theirs and the cookies are yours. A host’s defaults are usually sensible for core and WooCommerce, and they cannot know that a plugin you installed last week starts a session on every page. Run the probe script against your own site, whoever wrote the configuration. It takes a minute and tests the response your visitors actually get.

Does a cart cookie mean the whole site is uncached for that shopper?

On the rules above, yes: every page the shopper loads while the cart is not empty bypasses the cache, because the cookie travels with every request. That is normal and affects only people with items in a cart. The way to keep more pages cacheable for them is to stop the page itself being personal: load the mini cart count after the page renders instead of printing it into the HTML, and test the change on staging first.

Where do I read about the other cache layers?

Our layer-by-layer caching guide covers plugin caches, host caches, the CDN and the purge order. For slow first responses that rules cannot explain, the TTFB guide has the measuring steps.

The short version

  1. Log $upstream_cache_status, or read cf-cache-status and x-litespeed-cache, and count HIT, MISS and BYPASS.
  2. List the bypassed URLs. Cart and checkout are fine. Your home page and posts are not.
  3. Test each candidate cookie with curl -b and the probe script.
  4. Replace every wildcard rule with named cookies from the tables above.
  5. Never bypass on wordpress_test_cookie, woocommerce_recently_viewed, woocommerce_geo_hash or consent cookies.
  6. Check an anonymous request for Set-Cookie and remove whatever sets it.
  7. On Cloudflare APO, remember the prefix list is fixed, so stop the cookies being set instead.
  8. After any change, log in and confirm you see your own account page, then open a private window and confirm the same URL shows the login form.

Cookie rules are the cheapest performance change on a WordPress site, because they cost nothing to run. They let the cache you already pay for serve the visitors it was quietly excluded from.

Part of the Wbcom Designs family

The all-in-one WordPress community stack

Also ours: wbcomdesigns.comvapvarun.combrndle.com