DELTAWEB
All posts
Performance

Cache Errors on Multilingual Sites and How to Prevent Them

Caching can serve the wrong language, stale hreflang tags, a wrong currency or mixed cookie content. Fix cache keys, Vary headers and per-locale purging.

Cache Errors on Multilingual Sites and How to Prevent Them
11 minReading time
Arif KuruAuthor

When an English page of your export site shows Turkish text, the cause is often not the translation itself. Why does a CDN send an English copy to a buyer who opened the German page? In this article we walk through the four main symptoms that caching creates on multilingual sites, the likely cause of each one, and the first check to run. For the wider infrastructure picture, start with our guide on technical infrastructure for global reach.

Symptoms and likely causes

Cache errors rarely live at a single point. They usually appear in a layer that returns more than one answer for the same address. The table below lists the symptoms we see most often, along with the first place to look. Treat it as a diagnostic checklist: each row may need its own fix.

SymptomLikely causeFirst check
Wrong language is servedThe cache key is the URL alone, but the response changes with the languageRequest the same URL with different Accept-Language values and compare the bodies
hreflang looks outdatedOne page is held in cache with an old version while its cluster partners have changedCompare the hreflang lines in the cached HTML with the current source version
Wrong currency is shownThe price depends on the country, but the cache does not include that signal in its keyTest the price block with different country signals and compare the results
Cookie content gets mixed upA language cookie is read, but the response does not declare it with VaryInspect the Vary value and whether the cookie is sent with each request

The four errors in detail

Each symptom in the table has its own mechanism. The sections below explain how each one happens, what it looks like on a live page, and how to confirm it. We start with the most common error.

Wrong language: a cache key built from the URL alone

This is the most frequent error. A cache usually stores a response under a key that is built from the request address. If two visitors ask for the same address, the cache may hand the first visitor's response to the second, even when the language they want is different. When the server chooses the language from the Accept-Language header, the same URL is expected to produce different bodies for different requests. The cache does not see that difference unless the key or the Vary policy tells it to.

Consider a scenario (a fictional example): an exporter's home page is first opened by a German visitor, and the German version is stored in the cache. Later, a Turkish visitor requests the same address and receives the German page. The translation files may be correct. The fault lies in the cache's inability to tell the two requests apart.

The quickest test is to request the same address twice with different language headers and compare the lang attribute of each response. If both responses are identical, and they do not change when the language header changes, your cache key does not include the language.

Stale hreflang tags

hreflang annotations live either in the head of the HTML document or in an HTTP response header. When a page remains in cache with an old version, its hreflang cluster stays old too. The other language pages in the cluster may already be updated. The result is an inconsistent set: one page points to a partner that no longer matches, and the partner does not point back, or it points to an address that has since changed.

This inconsistency affects more than search engines. It can also confuse your language switcher and the sitemap you submit. The way hreflang, sitemaps and redirects fit together is worth designing as one system, not as three separate tasks. To check a cluster, compare the cached HTML of every page in it with the current source version, and confirm that the cache refreshes the tags whenever the page refreshes.

Implementation details for hreflang change over time. Before you rely on a specific search engine's handling, confirm the current behaviour in the official documentation. This article does not present any one engine's behaviour as a fixed rule.

Wrong currency

When prices or currencies depend on the visitor's country, that information is part of the response. If the cache keeps a single copy, it can show the currency of whichever country made the first request to everyone else. The problem is most visible on export sites, where quote pages and catalogue price rows carry the figures a buyer uses to judge the offer. A mismatched currency can undermine trust faster than a mistranslated sentence.

The key question is where the price is produced. If the server renders the price, the cache key needs a signal that identifies the currency, and that signal should be as narrow as possible. If the price is loaded by the browser after the page has rendered, the main HTML may stay the same and only the data request changes. Which approach fits depends on your page structure, the number of markets you serve and how your prices are calculated.

Showing a price based on the visitor's IP address carries its own risk. Crawlers can arrive from different regions, and a difference in content that depends on location may be treated as cloaking. Check the current policy in the official search engine documentation before you build geographic price logic.

Some sites store the language in a cookie. When the visitor changes the language, the cookie is updated and the server responds in the new language. The fault appears when the cookie changes the response but the cache does not know it. If the response does not declare the cookie dependency with Vary: Cookie or an equivalent, the cache may share one response across visitors whose cookies differ.

The opposite problem is also common. If the cookie is sent with every request, including requests for static pages, the cache hit rate drops, because each cookie combination creates a separate entry. When the cookie only exists to store a language choice, moving the language into the URL structure is usually the cleaner solution. Conflicts between a cookie and the Accept-Language header can also create redirect loops, which we cover in detail in our article on redirect loops when switching language.

Vary headers and the cache key

The Vary header tells a cache which request headers affect the response. A page that changes by language should carry Vary: Accept-Language. A page that changes by a cookie should carry Vary: Cookie. When the header is sent correctly, a cache can store separate copies for each language. The specific problems that appear when hreflang is involved, including Vary mistakes at the CDN layer, are covered in our article on hreflang with CDNs and caching.

Overhead view of cable trays in a modern data center
Photo: Brett Sayles / Pexels

Vary alone may not be enough. Many caches add the values of the headers listed in Vary to the key. If the Accept-Language header arrives in dozens of different variations, the cache fragments and the hit rate falls. For that reason, it is usually better to reduce the language dimension to a short, fixed set of values, such as tr, en or de, instead of passing the full raw header through.

The table below shows the components a cache key may contain and the reason each one is there.

ComponentExamplePurpose
Path/de/products/pumpThe address structure separates the languages
Language prefixdeKeeps each language version of the same product apart
Vary headerAccept-LanguageTells the cache which responses depend on the language header
Currency signalEURSeparates copies of the price block; included only when it is needed

CDN rules and per-locale purging

CDN providers let you configure caching behaviour through rules or page rules. The rules decide which request headers and cookies enter the cache key, and how long each type of response is stored. Default behaviour can differ between providers and between plans, so check the current defaults in your provider's documentation. This article does not assume how any particular service behaves today. For how hreflang and redirects can be handled at the CDN layer, see our article on edge SEO: managing hreflang and redirects at the CDN layer.

In practice, three groups of rules make a sound starting point:

  • A separate cache entry for every address that carries a language prefix
  • A key that matches the Vary header for responses that depend on a language header or a cookie
  • Long cache lifetimes for static assets only, and a short, verifiable lifetime for HTML
Neat stacks of books and papers arranged on white shelves
Photo: Cup of Couple / Pexels

Purging should also be done per locale. Clearing the whole site forces every language to revalidate at once, which adds load and makes it harder to see what changed. Instead, target only the addresses under the language prefix that changed. When you update a product page, check the German, English and Turkish copies as well, because the hreflang cluster changes together.

If you run automated purge rules, record which addresses were cleared after each publication. Without that record, one language can keep outdated content for days before anyone notices. Confirm in your provider's documentation which address patterns a purge request covers, since a pattern that looks broad may not match every variant you serve.

Designing the cache key step by step

It is far cheaper to decide the cache key before you write the page templates than to repair it afterwards. When you add a language, or restructure an existing one, the following sequence keeps the number of surprises low.

  1. Define one fixed, permanent address pattern for each language. The default language should follow the same structure as the others.
  2. List every request header and cookie that changes the response. If the template only varies by language, Accept-Language is enough. If a cookie also changes it, document that explicitly. If your frameworks handle language routing, follow the setup described in our article on Next.js i18n routing for multilingual sites.
  3. If a price or another regional field exists, decide whether it is produced on the server or in the browser. Add only the signal that is actually needed to the key.
  4. Match the Vary header to that list exactly. A header that is not in the list reduces the hit rate for no benefit, and a header that is in the list but missing from Vary causes mixed responses.
  5. Roll out the new key rule to one language first, then to the others. This makes it easier to see which layer caused a problem.

Each step has the same goal: to narrow the gap between what the cache stores and what the origin produces. As the rules grow, that gap becomes harder to watch. Keeping the rules small and documenting every change is usually the lowest-cost approach over the long run.

One mistake is worth naming separately. A team clears the cache for one language, then finds that another language still shows an old copy, and runs the same procedure again. A short checklist that verifies the purge result for each language prevents this. The checklist can be run again on several pages after every release.

Testing with different Accept-Language values

Do not guess whether the cache is behaving correctly. Test it. Request the same address with different Accept-Language values and compare the lang attribute, the title and the hreflang lines in each response. Record the header that shows whether the response came from the cache or from the origin server. The name and meaning of that header vary by provider, so consult your provider's documentation for the details.

A simple test sequence looks like this:

  1. Request the same address three times in a row with tr, en and de as the language header.
  2. Write the lang attribute, the title and the hreflang lines of each response into a table.
  3. If the first request in a language shows a miss and the next request in the same language shows a hit, the language split is probably working.
  4. Repeat the test for any page that changes with a cookie, using one client that sends the cookie and one that does not.
  5. After each release, repeat the same loop for at least one page per language.

A browser test with its language settings changed may not match exactly what the server receives. For that reason, combining command-line requests with a real browser check gives a more reliable picture. Make sure both tests are looking at the same version of the page, or you may compare two different releases without realising it.

One identity per language

A cache should never serve one language's page in place of another's. To prevent that, the language has to be carried consistently in the address, in the headers and in the cache key, and each change should be followed by a test of that language. Most of the time, the source of a cache error is the key rather than the translation.

Ask yourself one question: if a German visitor opened this page for the first time, would the response served from the cache be in German? If the answer is yes, your cache rule is doing its job.

FAQ

Frequently Asked Questions

  • Why does a cache serve the wrong language on a multilingual site?

    The cache usually stores responses under the URL, so if the URL is the same, it cannot tell two language requests apart. The first visitor's language may then be served to later visitors. Adding the language to the cache key and sending a correct Vary header fixes this.

  • Is the Vary header enough to fix language caching?

    Vary tells a cache which request headers a response depends on, but the cache key rules must also use that information. Keeping the language dimension to a short, fixed set of values helps protect the hit rate. Check your provider's documentation for how it treats Vary.

  • Why do hreflang tags stay outdated in the cache?

    A page held in cache with an old version keeps its old hreflang lines, even when its partners have been updated. That produces an inconsistent cluster that affects search engines and your language switcher. Compare the cached HTML of each page with the current source to find it.

  • How should prices in different currencies be cached?

    If the server renders the price, the cache key needs only the signal that determines the currency. If the browser loads the price later, the main HTML can stay the same while only the data request changes. Location-based content differences can resemble cloaking, so check the official search engine policy.

  • Does a language cookie break caching?

    It can, when the response changes with the cookie but does not declare it through Vary. Sending the cookie with every request also lowers the cache hit rate. If the cookie exists only to store a language choice, moving the language into the URL is usually cleaner.

  • How do you purge a cache for one language only?

    Send a purge request that targets only the address pattern of the changed language. Check the other language versions in the hreflang cluster as well, because they often change together. Confirm in your provider's documentation which patterns a purge covers.

  • How do you test language caching with Accept-Language?

    Request the same address several times in a row with different Accept-Language values, then compare the lang attribute, title and hreflang lines. Record the cache status header as well. Combining command-line requests with a real browser check gives a more reliable result.

  • Should every CDN rule be the same across the site?

    No. Static assets and HTML responses usually need different cache lifetimes and keys. Giving language-prefixed addresses their own entries leads to fewer surprises. Default behaviour differs between providers, so verify the rules against your provider's documentation.

Related Articles

No comments yet

Leave a Comment