# Check per-language cache handling

- Check 27.11 · Development and accessibility by language · Important
- Source: https://checklist-seo-geo.com/en/development-accessibility-language/check-per-language-cache-handling
- Check that every cache (page, object, proxy, CDN, ISR) keeps languages apart and is purged per language, on Nginx, Varnish, Cloudflare, WordPress, Laravel or Next.js.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/development-accessibility-language/check-per-language-cache-handling.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

A cache stores a response so it can serve it again without recomputing it. On a multilingual site, it must always return, for a given URL, the response in that URL's own language, whoever filled the cache. The task is to review each layer (page cache, object cache, reverse proxy, CDN, incremental regeneration, service worker) and check its cache key and its purge. Once the task is done, the language served depends only on the URL, and editing a translation updates every page concerned.

## Why it matters

A cache key is the identifier under which a response is stored. By default, it is the URL, sometimes without the host name. As long as each language has its own URL, all is well. Incidents come from four situations:

- **Same URL, several languages**: the root `/`, or a page that picks its language from a cookie or the `Accept-Language` header. The first visitor fills the cache, and everyone after them gets that visitor's language, crawlers included.
- **Key without the host name**: with subdomains (`de.example.com`) or country domains, two languages share the same cache entry for `/tarifs/`.
- **Fragments without the language**: the menu, the footer or a product block are cached under a shared key (`menu-principal`). A French page shows the German menu.
- **Partial purge**: a translation changes its slug, only its page is purged, and the other languages keep announcing the old URL in their hreflang annotations and their switcher.

These defects are intermittent: they depend on who filled the cache first. They therefore often slip past manual tests, but not past crawlers, which crawl with no cookie and no `Accept-Language`. When Googlebot receives a German page under a French URL, it may index it as is.

## What it improves

- **Reliable indexing of each language**: the response served to crawlers is the one for the URL, not the previous visitor's.
- **Visitor experience**: no more pages or menus in another language.
- **Up-to-date hreflang and switcher**: the purge covers every linked translation.
- **Cache hit rate**: a simple key (URL and host) avoids fragmenting the cache by browser language.
- **Citations in AI answers**: AI crawlers receive the right language under each URL. Indirect effect.

## How to check

**1. Does a URL's language hold up against the visitor's headers?** Fill the cache as a German visitor, then read the page without a language header:

```bash
url=https://example.com/fr/tarifs/
curl -s -o /dev/null -H "Accept-Language: de-DE,de;q=0.9" -H "Cookie: lang=de" "$url"
curl -s -D - "$url" | grep -i -E "^(age|cf-cache-status|x-cache|x-vercel-cache|x-litespeed-cache|vary):|<html"
```

Expected result: a cache indicator (`HIT`, or an `age` greater than 0) and `lang="fr"`. Replace `lang=de` with the actual name of the language cookie, visible in the Application tab of the developer tools. Run the test the other way round too, filling the cache in French on a German URL.

**2. Are hosts kept apart?** With subdomains or country domains, request the same path on two hosts and compare the `lang` attribute:

```bash
for host in example.com de.example.com en.example.com; do
  printf '%-20s ' "$host"
  curl -s "https://$host/tarifs/" | grep -o -i '<html[^>]*lang="[^"]*"'
done
```

**3. Do fragments follow the language?** On one page per language, check the language of the menu, the footer, the cookie banner and the "related articles" blocks. A word from another language in these areas points to a badly keyed object cache.

**4. Does the purge cover the translations?** Change the slug of a translation, then check in the other languages that the switcher and the hreflang annotations point to the new URL:

```bash
curl -s https://example.com/fr/tarifs/ | grep -o '<link rel="alternate" hreflang="[^"]*" href="[^"]*"'
```

**5. `Vary`**: a `Vary: Accept-Language` or `Vary: Cookie` header on inner pages means the response depends on the visitor's language, which should only apply to the root.

## How to implement

### Before you start

List the caches, from the browser to the database:

| Layer | Example | Expected key | Purge when a translation is updated |
|---|---|---|---|
| CDN | Cloudflare, CloudFront, Fastly | Scheme, host, path | URLs of all linked translations |
| Reverse proxy | Varnish, Nginx `fastcgi_cache` | Scheme, host, path | Same |
| CMS page cache | WP Rocket, LiteSpeed Cache | URL, one file per language | Same, plus the language's home page and listings |
| Object cache and fragments | Redis, Memcached, transients | Fragment name + language | Fragments of the language concerned |
| Incremental regeneration | Next.js ISR | Path with language prefix | Paths of all translations |
| Service worker | Workbox | URL | New version of the service worker |

Common rules:

- **The language comes from the URL**: a cache keyed on the full URL is then correct with no tuning. If an inner page changes language based on a cookie or a header, fix that first: see [avoid handling language only through cookies/JS](https://checklist-seo-geo.com/en/international-architecture/avoid-handling-language-only-through-cookies-js).
- **The root is a special case**: if `/` routes visitors based on their language, keep it out of the shared cache, or vary the cache by normalized language (see Cloudflare).
- **Purge by translation group**: on every edit, purge the edited URL and those of all its translations, since they show its URL in their hreflang annotations.

### Nginx

Versions: Nginx 1.18 and later.

Check that the cache key includes the host, which is essential with subdomains or several domains:

```nginx
fastcgi_cache_key "$scheme$request_method$host$request_uri";
# or, for proxy_cache:
proxy_cache_key "$scheme$request_method$host$request_uri";
```

The default value of `proxy_cache_key` is `$scheme$proxy_host$request_uri`: `$proxy_host` is the upstream server's host, the same for every language if they go through the same backend. Replace it with the `$host` version.

Exclude the root from the cache if it depends on the visitor's language, in the `server` block:

```nginx
location = / {
    fastcgi_cache_bypass 1;
    fastcgi_no_cache 1;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}
```

Adapt the socket. Reload with `sudo nginx -t && sudo systemctl reload nginx` and empty the cache folder.

### Varnish

Versions: Varnish Cache 6.0 LTS to 8.0 and Vinyl Cache 9, the open source project's new name since 2026 (the `varnish…` commands become `vinyl…`, for example `vinyld`).

Varnish's built-in `vcl_hash` function combines the URL and the `Host` header: hosts stay separate as long as you do not override it. If your VCL defines its own `vcl_hash`, keep the host:

```vcl
sub vcl_hash {
    hash_data(req.url);

    if (req.http.host) {
        hash_data(req.http.host);
    } else {
        hash_data(server.ip);
    }

    return (lookup);
}
```

Also check that `vcl_recv` does not strip the language cookie on a page whose language depends on it, and that the root goes straight to the server if it routes visitors:

```vcl
sub vcl_recv {
    if (req.url == "/") {
        return (pass);
    }
}
```

To purge a translation group, use a ban on an expression that covers the URLs concerned, for example `varnishadm 'ban req.url ~ "^/(fr/tarifs|de/preise|en/pricing)/"'`.

### Cloudflare

Versions: Cloudflare dashboard, all plans (custom cache keys: Enterprise), November 2026.

Cloudflare's default cache key contains the full URL, host included: languages in subfolders, subdomains or separate domains are kept apart with no tuning.

Points to check:

- **`Vary` ignored by default**: Cloudflare disregards `Vary` (except `Accept-Encoding`) unless a Cache Rule turns on the Vary setting. A page that varies on `Accept-Language` and is cached by a rule will therefore be served in a single language. If you need to cache a root that routes by language, create a [Cache Rule](https://dash.cloudflare.com/?to=/:account/:zone/caching/cache-rules) limited to `http.request.uri.path eq "/"`, turn on Vary with the "normalize" action on `Accept-Language` and the list of your languages, and have the origin send `Vary: Accept-Language`. Otherwise, exclude `/` from the cache.
- **Language cookies**: a Cache Rule that caches HTML ignores cookies in the key. A page whose language depends on a cookie will get mixed up. Custom cache keys (cookie, headers, country, language) are reserved for the Enterprise plan.
- **Purge**: `Caching > Configuration > Purge Cache > Custom Purge`, URL option, listing every translation. Through the API, send the list of URLs in a single `purge_cache` call.

### AWS

Versions: Amazon CloudFront console and AWS CLI v2, November 2026.

On **CloudFront**, the cache key is defined by each behavior's cache policy. Open the [CloudFront console](https://console.aws.amazon.com/cloudfront/v4/home), `Policies > Cache` section, and check:

- that the `Host` header is forwarded or included if several language domains point to the same distribution;
- that `Accept-Language` and language cookies are not part of the key for inner pages, which would fragment the cache for no reason;
- that the root's behavior, if it routes by language, uses `CachingDisabled` or a redirect function that runs before the cache.

Purge a translation group with a single invalidation:

```bash
aws cloudfront create-invalidation --distribution-id DISTRIBUTION_ID --paths "/fr/tarifs/" "/de/preise/" "/en/pricing/"
```

### LiteSpeed

Versions: LiteSpeed Web Server 6 and OpenLiteSpeed 1.7 and 1.8, LiteSpeed Cache for WordPress plugin 7.

LSCache keeps URLs apart like other page caches. With the LiteSpeed Cache for WordPress plugin, what gets purged on publication depends on the rules under `LiteSpeed Cache > Cache > Purge` (automatic purge on publish or update) and on the translation plugin: do not assume linked translations are purged. Check that the edited translation and its equivalents are purged, with the `x-litespeed-cache: miss` header on the next request, and purge them by hand if they are not.

### WordPress

Versions: WordPress 6.4 and later, WP Rocket 3, WPML 4 or Polylang 3.

- **Page cache**: WP Rocket supports WPML and Polylang. With Polylang, the WP Rocket documentation states that each visitor's first visit is not cached while the language is being detected, and that caching kicks in once the `pll_language` cookie is set. With WPML, per-language purging and preloading assume the directory URL format. For other cache plugins, check their documentation for compatibility with your translation plugin.
- **Object cache and transients**: a theme or plugin that stores a menu or a list under a fixed key shares it across languages. Add the language to the key:

```php
$lang = function_exists('pll_current_language') ? pll_current_language() : apply_filters('wpml_current_language', null);
$key = "related_posts_{$post_id}_{$lang}";
$related = get_transient($key);

if ($related === false) {
    $related = theme_related_posts($post_id);
    set_transient($key, $related, HOUR_IN_SECONDS);
}
```

- **Purge**: after editing a translation, purge its equivalents too. With WPML or Polylang, WP Rocket lets you clear and preload the cache of one language or of all of them (`Clear and preload cache`).

### Laravel

Versions: Laravel 11 to 13; spatie/laravel-responsecache 8 (Laravel 12 and 13) or 7 (Laravel 11).

Add the current language to every fragment cache key:

```php
$locale = app()->getLocale();

$menu = Cache::remember("menu.main.{$locale}", now()->addHour(), fn (): Collection => Menu::forLocale($locale)->items());
```

With `spatie/laravel-responsecache`, check that the language is part of the URL (route prefix): the package stores responses by URL. If a page depends on the session for its language, it must not be cached. To purge a translation group, forget the URLs of each language (`ResponseCache::forget(['/fr/tarifs', '/de/preise'])`) or tag responses by content and clear the tag (`ResponseCache::clear(['page-42'])`).

### Next.js

Versions: Next.js 15 and 16 (App Router).

- **Incremental regeneration**: each language is a separate path (`/fr/tarifs`, `/de/preise`). When a translation is published, revalidate all linked translations:

```ts
// app/api/revalidate/route.ts
import { revalidatePath } from 'next/cache';

export async function POST(request: Request) {
  const { paths } = await request.json();

  paths.forEach((path: string) => revalidatePath(path));

  return Response.json({ revalidated: paths });
}
```

Protect this endpoint with a secret shared with the CMS. With tags, tag data requests by content rather than by language, so that a single invalidation covers every translation. Since Next.js 16, `revalidateTag` takes a second argument (`revalidateTag('page-42', 'max')`, or `{ expire: 0 }` for immediate expiry); the single-argument form, used in Next.js 15, is deprecated.

- **Data cache**: with the `use cache` directive (stable since Next.js 16 with the `cacheComponents: true` option, experimental in Next.js 15), the function's arguments are part of the key; pass the language as an argument rather than reading it from a global variable or a cookie.
- **Proxy**: if `proxy.ts` (`middleware.ts` before Next.js 16) routes the root based on `Accept-Language`, add `Vary: Accept-Language` and `Cache-Control: private, no-store` to that response.

### Shopify

Versions: Shopify, all plans, November 2026.

Shopify's cache keeps each language's URLs apart and is purged on publication: nothing to configure. Only check apps that cache their own blocks (reviews, recommendations): their text must follow the page's language.

## Common mistakes

- **Caching a root that routes by language**: the first visitor decides the language for everyone else.
- **Cache key without the host** with language subdomains: `de.example.com/tarifs/` receives the `example.com/tarifs/` page.
- **Fragments cached without the language**: menus, footers and widgets in the wrong language on pages that are otherwise correct.
- **Adding `Vary: Accept-Language` to every page**: the cache splits into as many entries as there are browser language combinations, and several CDNs ignore it or refuse to cache.
- **Purging only the edited page**: the other languages show the old slug in their hreflang annotations.
- **Testing only once**: the defect only shows up once the cache has been filled by a visitor in another language.

## Frequently asked questions

### Should you send the Vary: Accept-Language header?

Only on responses that really change with the browser's language, which in practice means a root that routes visitors. When each language has its own URL, the cache relies on the URL and Vary is useless. On every page, it fragments the cache, and some CDNs ignore it by default or refuse to cache the response: Cloudflare only takes it into account if a Cache Rule turns it on.

### Why does a visitor sometimes see the page in the wrong language?

Most often, a cache has stored two different responses under the same key: a page whose language depends on a cookie or on the Accept-Language header, language subdomains sharing a key without the host name, or a fragment such as the menu cached without the language. The defect is intermittent, because it depends on the language of the visitor who filled the cache first.

### Should every language be purged when a translation is edited?

Purge at least the edited page and all its translations. Each translation shows the URLs of the others in its hreflang annotations and in its language switcher: if the slug changes, pages that were not purged point to an old address. Listings in the same language (home page, category, feed) also need purging if the title or the excerpt changed.

### Should the language cookie be part of the cache key?

No, if the URL carries the language: the cookie only stores a choice and does not change the page's content. Adding it to the key multiplies entries for no benefit. If a page changes language based on the cookie, it is the architecture that needs fixing, because crawlers, which have no cookie, will only ever see one language of that page.

## Resources

- [MDN: Vary header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Vary)
- [Google Search Central: Localized versions of your pages](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=en)
- [Nginx: proxy_cache_key](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_key) and [fastcgi_cache_key](https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache_key)
- [Varnish: Built-in VCL](https://varnish-cache.org/docs/trunk/users-guide/vcl-built-in-code.html)
- [Cloudflare: Cache keys](https://developers.cloudflare.com/cache/how-to/cache-keys/) and [Vary support](https://developers.cloudflare.com/cache/concepts/vary/)
- [Amazon CloudFront: Cache policies](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html)
- [WP Rocket: Multilingual plugins](https://docs.wp-rocket.me/article/76-translation-multilingual-plugins)
- [Next.js: revalidatePath](https://nextjs.org/docs/app/api-reference/functions/revalidatePath)

Next steps: [check the CDN and language variants](https://checklist-seo-geo.com/en/development-accessibility-language/check-cdn-language-variants), [test without cookies](https://checklist-seo-geo.com/en/development-accessibility-language/test-without-cookies) and [configure browser and server caching](https://checklist-seo-geo.com/en/performance-core-web-vitals/configure-browser-server-caching).
