# Prevent Concurrent Rebuilds of an Expensive WordPress Transient

https://ferkesh.net/uk/baza-znan/stattia/wordpress-expensive-transient-rebuild-concurrency

Several requests can see the same transient miss at once and all start a costly rebuild. Use a harmless, instrumented staging fixture to measure how often this happens before adding coordination.

![Workflow. Two misses. Atomic shared add. Single rebuild. Stalled worker test.](https://ferkesh.net/kb-media/ferkesh-guide-diagrams-batch-14a.svg#wordpress-expensive-transient-rebuild-concurrency)

## Reproduce two misses at the same time

Choose one derived public value, such as a count from a test catalog. Record rebuild starts and ends with a fixture request ID. Start two concurrent requests after removing only the fixture key. If each request begins the expensive calculation, you have a repeatable concurrency case.

## Coordinate at the correct scope

Use a short-lived, atomic add operation in the persistent backend shared by all workers that handle this key. WordPress wp_cache_add adds a value only if the key is absent, but its normal in-memory cache is request-local. Confirm the installed drop-in gives the required cross-worker atomic behavior. Use matching site, group and data dimensions for the value and coordination key.

## Design for expiration and failure

After acquiring the key, recheck the cached value. Keep competing requests bounded using a safe stale copy or a brief fallback, as the workload allows. Test a stalled writer, an expired provisional key and a failed rebuild. Use backend-supported ownership when releasing a lease to avoid deleting a newer worker's key after expiration. Never serve stale permissions, prices or similarly sensitive data without an explicit product rule.

## Expected result

The evidence shows one rebuild in the overlapping case and recovery after a stalled worker. Preserve the original simpler behavior for workloads where concurrent rebuilds are inexpensive.

## Related guides

- [How to Handle WordPress Transient Cache Misses](https://ferkesh.net/knowledgebase/article/wordpress-transient-cache-misses)
- [How to Tell a WordPress Object Cache from a Page Cache](https://ferkesh.net/knowledgebase/article/wordpress-object-cache-vs-page-cache)

## Official references

- [WordPress Transients API](https://developer.wordpress.org/apis/transients/)
- [WordPress wp_cache_add behavior](https://developer.wordpress.org/reference/functions/wp_cache_add/)

Ferkesh Hosting. Last reviewed November 27, 2026.
