Docs
Caching and CDN
How LocalePro caches translations, what it tells page caches and CDNs, what gets invalidated when, and what to purge after an import.
Translations live in your database. On top of that sit two caches of LocalePro’s own, and in front of the whole site usually sits a page cache or a CDN that LocalePro does not control. This page is about how the three fit together.
The translation cache
Every translated sentence is looked up by a hash of its source text. Before that lookup reaches the database, two layers answer first:
- A per-request dictionary. Anything resolved once on a page is not looked up again on the same page.
- The WordPress object cache, group
localepro. Each entry is one effective translation for one language, or a marker meaning “known to have no translation yet”. Entries live for one day.
Lookups are bulk: a page asks for every hash it needs in one call, and the object cache is read with one wp_cache_get_multiple. Without a persistent object cache (Redis, Memcached), the object cache lasts only for the request, so each page reads its translations from the database. The lookup is still bulk; LocalePro’s own tests hold a warm page to at most one translation query.
Recipes
Some sentences are composed from others. "Shoes" has been added to your cart. has no row of its own; it is the translation of a template with the translation of Shoes put back in. The cache remembers the recipe (which template, which parts) so a later request composes the sentence from cached parts instead of asking the database for a row that does not exist. The composed sentence is never cached itself. Editing a part, such as Shoes, evicts it, and the next composition picks the change up.
The generation number
There is no reliable way to delete one cache group across every object-cache backend. So every key carries a generation number, stored in the autoloaded option localepro_cache_generation. Flushing the cache increments that number: everything written under the old one becomes unreachable at once and expires on its own within the day. On a backend that supports wp_cache_flush_group, the old group is also cleared immediately to free the memory.
A flush happens when:
- The source language changes. Hashes include the source language, so every page hashes differently afterwards. The old entries are flushed rather than left to sit, because a hash that collided across two languages would serve the wrong original’s translation.
- A glossary rule changes. Every machine translation whose source mentions the term is cleared in the languages the rule touches, and the cache is flushed so the cleared rows stop being served. Manual and locked rows are not touched.
There is no cache-flush button. Day-to-day, individual entries are evicted as rows change, as described next.
What gets invalidated when
When a stored translation changes, its entry (and any recipe keyed on it) is removed from the object cache, and the action localepro_cache_invalidate fires. The action receives two arguments: a post id, or 0 when the change is not about one post, and a language code, or an empty string for all languages.
| When | Post id | Language |
|---|---|---|
| A published post or page is saved | the post | all |
| A row is edited, reverted, unlocked, regenerated, or deleted on the Translations screen | 0 | the row’s |
| A row is written by an import | 0 | the row’s |
| A glossary rule changes | 0 | each language touched |
| A background quality upgrade improves a translation | 0 | the language |
| Improve with AI runs on a post | the post | the language |
This action is the integration point for page caches and CDNs. LocalePro ships no purge adapters of its own; a short snippet in your theme or a must-use plugin hooks the action and calls your cache’s purge API. Because every language is a subdirectory, the paths to purge are the translated addresses: /es/about-us/ for post 42 in Spanish, or everything under /es/ when the post id is 0.
add_action( 'localepro_cache_invalidate', function ( int $post_id, string $locale ): void {
// Purge /{locale}/... in your page cache or CDN here.
}, 10, 2 );
Page caches and CDNs
Vary by path
Languages are subdirectories (/es/, /fr/), so a page cache keyed on the URL already keeps languages apart. No cookie or header needs to be part of the key for ordinary pages.
Two cases add headers:
- Browser-language redirect. When Send first-time visitors to the language their browser asks for is on, source-language responses carry
Vary: Accept-Language, Cookie, because the redirect reads the visitor’s cookie before the header. On WordPress VIP, whose page cache ignoresVary, the redirect runs in the browser instead, so cached HTML stays the source page for everyone. - Content loaded after the page. When Translate content loaded after the page renders is on, the language of an AJAX or REST response is read from request headers, not the URL. Those responses carry a
Varyon the headers involved and aContent-Language, so a shared cache does not hand a Spanish payload to an English caller.
Every page response also carries Content-Language.
Failed translations are never cached
If a provider call fails mid-page, the page still renders with source text where the translation should be. That page is the wrong thing to store. LocalePro defines DONOTCACHEPAGE, which most page cache plugins honour, and sends no-cache headers. The filter localepro_prevent_caching_on_failure turns this off.
Loopback renders
Reading a page’s strings on the Translations screen, and warming pages in the background, both fetch the translated page from your own server. The inventory render carries a localepro_inventory query argument and must bypass the page cache; a cached copy would answer without running the read. Hosts that block loopback requests cannot build inventories or warm pages.
First-request translation and warm-up
Two settings under Settings → Content decide when a provider is called.
Translate missing text during the first request is on by default. A sentence not yet in memory is translated while the first visitor waits, stored, and served from memory after that. With it off, pages are served from memory only: a missing sentence stays in the source language, is recorded in the cache as a miss, and is not sent to a provider.
Translate new content in the background when a post is saved is off by default. When on, saving a published post or page queues one background job per language through WP-Cron, spaced five seconds apart so a slow or killed cron run costs at most one language. Each job fetches the translated address of the post from your own server, the same path a visitor takes, with a 60-second timeout. Languages set to Your own version or Off for that post, and anything an exclusion rule covers, are skipped. Which post types qualify is filterable with localepro_warmup_post_types; the default is pages and posts.
A separate queue warms AJAX and REST endpoints that were served untranslated. At most 50 such jobs wait at once (filter localepro_pending_endpoint_limit); beyond that, a request is dropped rather than queued, which costs one more untranslated response.
One provider call per new page
When several visitors hit a brand-new page at the same moment, each would miss the cache and call the provider for the same sentences. LocalePro takes a short lock (30 seconds, filter localepro_translation_lock_ttl) before sending, so only one request pays. The lock coordinates across PHP workers only with a persistent object cache; without one, each request runs alone and the lock is a no-op.
After a bulk import
An import evicts each written row from the object cache and fires localepro_cache_invalidate for it. Nothing else is purged for you. After importing translations for a language, purge that language’s subdirectory in your page cache and CDN, or the old pages keep being served until they expire.
Redis and object-cache drop-ins
With a persistent object cache, a warm page’s translations are answered from memory with no database query, the “known miss” markers stop repeat database lookups for sentences that have no translation yet, and the one-call lock above works across workers. Entries expire after one day on their own, and a generation flush makes the old ones unreachable without needing the backend to support group deletion.
Measured overhead
The plugin’s own benchmark (Html_Bench_Test, run with LOCALEPRO_BENCH=1) measures the time LocalePro adds to a page whose translations are already in memory. The figures below are the first baseline, recorded 2026-09-14 on a ddev container with PHP 8.3, warm memory, a mock provider (no network), 20 iterations, means:
| Profile | Size | Segments | Total |
|---|---|---|---|
| small | 38 KB | 452 | 18.4 ms |
| medium | 144 KB | 1,652 | 73.4 ms |
| large | 455 KB | 5,152 | 233.2 ms |
Read them with their caveats. They exclude provider latency entirely; a first visit to an untranslated page waits on DeepL, Google, or Microsoft on top. The cost scales with the number of sentences on the page, not its byte size. And the link-rewriting share is under-measured: the test site has almost no rewrite rules, and on a production site with a large rewrite table that part is larger. The plugin’s documentation treats these as a floor, and the large profile as the case still being worked on.
Related
- Usage and spend, for the monthly ceiling and the staging guard.
- Hooks and filters, for the full filter list.
- Troubleshooting, when a page looks stale or half translated.