All posts

Full page cache and checkout: when Varnish serves the wrong page

Full page cache, built in or through Varnish, is the biggest speed win on a Magento store. It is also a quiet source of checkout bugs, because a cached page looks perfectly healthy to anyone who checks it from outside.

Free checkout scan

Enter your store address. A real browser adds a product to the cart and walks the checkout up to the payment step, like a customer, and shows you every step with a screenshot.

  • Free, no account
  • Stops before payment, no order
  • Nothing to install
· Updated · 3 min read
A neat stack of paper sheets

How Magento splits public and private

A cached page is the same for everyone. Magento keeps it that way by leaving the personal parts out: the mini cart, the customer name and the form key are loaded afterwards by JavaScript, from customer/section/load, and stored in the browser. Cart, checkout and account pages are not cached at all.

When that split works, everyone gets a fast page and their own cart. When it breaks, one shopper’s state or an expired form key is served to many.

Browsernew visitorPage HTML · Varnishpublic, cached, same for allcustomer/section/loadprivate, never cachedMagentocart · name · form keycart & checkout pagesnever from cache
The page comes from cache and is the same for everyone. The cart, name and form key come from customer/section/load, which must never be cached.

How it shows up

The symptoms are strange and intermittent: “Invalid Form Key” on add to cart, a mini cart that shows an empty basket, prices that do not match what the cart charges, a checkout that loads but will not advance. Refreshing sometimes fixes it, which makes it easy to dismiss.

A request that only checks for a 200 response never sees this. The page loads, fast, from cache. Only a real flow, adding a product, opening the cart and moving through checkout, shows that the state behind the page is wrong.

Check the headers

Ask the store whether a page came from cache. A product page should be cacheable; the cart and checkout must not be:

bash
for u in / /checkout/cart/ /checkout/; do
  echo "== $u"
  curl -sI "https://example.com$u" | grep -iE "^(cache-control|age|x-cache|x-magento-cache-debug)"
done
X-Magento-Cache-Debug (HIT or MISS) only appears in developer mode. In production, a growing Age header or your CDN’s X-Cache tells the same story.
PageExpectedProblem if
Home, category, productCacheable (`public`, Age grows)Never cached: FPC is effectively off
/checkout/cart/Never cached (`no-store`, `no-cache`)Age above 0 or a HIT
/checkout/Never cachedAge above 0 or a HIT
customer/section/loadNever cachedSame response for different sessions

The two classic mistakes

A block with cacheable="false" in a layout file makes the whole page uncacheable. Put it in default.xml and full page cache is off for every page of the store, which is a performance problem rather than a checkout bug, but it is common. Find such blocks:

bash
grep -rn --include=*.xml 'cacheable="false"' app/code app/design vendor/*/*/view/frontend/layout | grep -v "/checkout_\|/customer_"

The opposite mistake is worse: a hand-edited Varnish configuration that strips cookies or caches responses Magento marked private. Generate the VCL from Magento for your Varnish version and keep it in the repository with the code:

bash
bin/magento varnish:vcl:generate --export-version=6 > varnish/default.vcl
Purge after configuration changes

A price, tax or shipping change in the admin does not always clear every cached page that shows it. Purge Varnish and the CDN after changes that affect what the cart charges.

Catch it from outside

Run the checkout flow on a schedule as a new visitor each time. A fresh session is exactly what a cache mistake punishes, so it is the best way to catch one before customers report it. Related: CDN caching rules on WooCommerce and Redis sessions and lost carts.

Check your own store now with the free Magento checkout test: it walks the checkout in a real browser, Luma or Hyvä, and shows the step where it stops.

Step-by-step fix when the product never reaches the cart: Magento 2 add to cart not working.

Find out your checkout broke before your customers do.

Real checkout checks for Magento and WooCommerce · free plan · no card requiredMagento checkout monitoring →
FAQ

Common questions

Still have a question?More answers, and a way to reach us.Support →
01Should the Magento checkout be cached?

No. Cart, checkout and customer account pages, and the customer-data sections they load, must never come from the full page cache.

02How do I know Varnish is serving the wrong page?

Customers see another cart, a stale mini cart, wrong prices after a change, or a checkout that loses the session. The Age and X-Cache headers, or X-Magento-Cache-Debug in developer mode, show whether a page came from cache.

03How do I fix it?

Generate the VCL from Magento for your release, keep cacheable="false" blocks off shared layouts, and purge after configuration changes.