Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Magento cache serving wrong store view: how to find and fix it

OPS-261Medium impactPartlyBy FunnelGuardPublished Updated
On this page

What this issue is

Magento lets one install run several store views, for example an English view in USD and a German view in EUR. Each has its own language, currency, prices and sometimes tax rules. To stay fast, Magento caches whole pages (the full page cache, built in or through Varnish).

The problem appears when the cache decides two requests are the same when they are not. A page built for one store view is then stored and handed to visitors of another. The visitor sees the wrong language, the wrong currency or the wrong prices, and sometimes a cart or checkout in the wrong store.

Why it costs you leads or sales

Visitors who land on a page in the wrong language or currency often leave. Wrong prices cause failed orders, refund requests or orders you cannot fulfil. Ad traffic aimed at one market lands on another market's page, so you pay for clicks that cannot convert. The fault is also intermittent: it depends on which visitor warmed the cache first, so it is easy to miss.

How a cache mix-up loses a sale
  1. English visitorLoads /product, page cached
  2. Cache keyDoes not include store view
  3. German visitorReceives English page in USD
  4. CheckoutVisitor leaves or order is wrong

A German visitor gets a cached English page.

Conversion by store viewExample numbers
Conversion by store view (example)Correct store view: 2.4 %; Wrong store view cached: 0.6 %0122.40.6Correct store viewWrong store view cach…%

Example: conversion rate for the German store view before and after the cache serves it the wrong store. Numbers are illustrative.

How to check if your site has it

Check each store view
  1. Open every store view in a clean browser

    Use a private window or a different device for each URL or domain. Note the language, currency and a sample price.

  2. Switch store view and reload

    Use the store switcher, then reload the page twice. If the first load is right and later loads are wrong, cache is the likely cause.

  3. Inspect response headers

    In browser dev tools, Network tab, open the page request. Look at X-Magento-Cache-Debug (HIT or MISS), Age and Vary headers.

  4. Compare with the cache bypassed

    Request the page with a cache-busting query such as ?nocache=1 from a test. If it is correct only then, the cached copy is wrong.

  5. Check from different regions

    A CDN may cache per location. Test from the countries you sell to.

Compare headers for two store viewsbash
curl -sI https://example.com/ | grep -iE 'x-magento-cache|age|vary|content-language'
curl -sI https://example.com/de/ | grep -iE 'x-magento-cache|age|vary|content-language'

How to fix it

Common causes are store views that share one URL and rely only on a cookie, a Varnish or CDN rule that strips the store cookie or ignores the host, and a wrong base URL for a store view. The fix is to make the store view part of what identifies a page.

Fix the cache key
  1. Give each store view its own URL

    In Stores > Configuration > General > Web, set a distinct Base URL for each store view, or turn on Add Store Code to URLs. Separate domains or paths are the safest cache keys.

  2. Check store view scope settings

    Confirm each website and store view maps to the right code (Stores > All Stores). A wrong code in the web server mapping sends visitors to the wrong view.

  3. Review the web server mappingCustom code

    If you use MAGE_RUN_CODE and MAGE_RUN_TYPE, make sure each host or path sets the right values.

  4. Fix Varnish or CDN rules

    Make sure the hash includes the host and the store cookie, and that the cookie is not stripped. Use the VCL exported from Stores > Configuration > Advanced > System > Full Page Cache, then reload Varnish.

  5. Flush the caches

    Run the flush commands below, then purge your CDN.

Flush Magento cachesbash
bin/magento cache:clean
bin/magento cache:flush
Example: set the store per host in nginxnginx
map $http_host $MAGE_RUN_CODE {
    default en_us;
    shop.example.de de_de;
}
fastcgi_param MAGE_RUN_TYPE store;
fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;

How to confirm it's fixed

Confirm
  • Each store view URL shows its own language, currency and prices on first and repeat loads
  • Headers show HIT on repeat loads and the content stays correct
  • Switching store view and reloading keeps the chosen view
  • Cart and checkout show the right currency and tax for each view
  • A CDN-served copy from each target country is correct

How to prevent it happening again

Prevention
  • Use separate domains or paths per store view
  • Re-export and review the Varnish VCL after every upgrade
  • Test each store view after changing CDN or cache rules
  • Flush caches after changes to store view, currency or price settings
  • Add a store view check to your release checklist

How FunnelGuard handles this

FunnelGuard detects this issue only partly. It runs your real customer journeys on a schedule from the EU or the US, checks each step, and alerts you with a screenshot and a likely cause when a journey breaks. That can catch a wrong store view when it breaks a step, for example a form, button or checkout that fails on the cached page. A failure is re-checked from a second region before one alert goes out.

FunnelGuard does not compare the language, currency or prices of each store view for you, and it does not inspect your Varnish or CDN configuration. A page in the wrong language that still works will not trigger an alert. Cover the rest by hand: open each store view in a clean browser after every deployment or cache change, check currency and a sample price, and compare cache headers as shown above.

Questions people ask

Why is my Magento store showing the wrong language or currency?

Most often the full page cache has stored a page from one store view and serves it to visitors of another. This happens when the cache key ignores the store view, for example when views share a URL and differ only by cookie. Give each store view its own URL or make the cache vary on the store cookie.

How do I fix Magento serving the wrong store view?

Set a distinct Base URL for each store view, check the store code mapping, and fix Varnish or CDN rules so they include the host and store cookie. Then run bin/magento cache:flush and purge your CDN. Test each store view afterwards.

Does Varnish cause the wrong store view to show in Magento?

It can if the VCL ignores the host or strips the store cookie, so pages from different store views share one cache entry. Export the VCL from the admin for your version, apply it and reload Varnish.

How do I test if Magento cache is serving the wrong store?

Load each store view in a clean private window, reload twice and compare language, currency and prices. Check the X-Magento-Cache-Debug and Vary headers in dev tools. If the page is correct only with the cache bypassed, the cached copy is wrong.

Will flushing the Magento cache fix the wrong store view for good?

Flushing removes the bad pages but does not fix the cause. If the cache key or Varnish rule is wrong, the problem returns as soon as the wrong copy is cached again. Fix the key first, then flush.

Can FunnelGuard detect Magento showing the wrong store view?

Only partly. It catches the problem when it breaks a journey step, such as a form or checkout, and alerts you with a screenshot. It does not compare language, currency or prices across store views, so check those by hand.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.