After a deploy, customers see the old version of the page. Three caches are between them and the new code: Cloudflare at the edge, LSCache on the cPanel host, and Redis as the object cache. Each has its own purge mechanism, and purging the wrong one wastes time and confuses the customer. The right pattern is layer-specific and ordered: edge first, server cache next, object cache last. Skipping a layer means the next request rebuilds the cache from the stale layer below it.
What’s happening
The cache hierarchy on a typical cPanel WordPress site:
- Browser cache — controlled by Cache-Control headers, invalidated by changing the URL (hashed filenames) or by
max-age=0on HTML. - CDN cache (Cloudflare/BunnyCDN) — purgable via API or dashboard. URL-level or wildcard.
- LSCache (LiteSpeed full-page cache) — purgable via plugin or via
lscache_helpercommand. Tag-based. - Object cache (Redis/Memcached) — purgable via
wp cache flush,FLUSHDB(dangerous), or selective key deletion. - OpCache — invalidated on file mtime change (if configured) or by
opcache_reset()from a PHP script. - Database query cache — implicit, invalidated on write.
A deploy that changes a CSS file but not its filename: invalidate browser cache by changing the URL (hash), then purge Cloudflare for that path, then purge LSCache, then optionally clear object cache if any plugin stored the asset URL there. A deploy that changes PHP logic: purge OpCache, restart PHP-FPM, then purge everything else.
How to verify
After a purge, the next request should be a miss everywhere up to the point where you successfully invalidated:
curl -I -H "Cache-Control: no-cache" https://example.com/page
# Look for: cf-cache-status: MISS, x-litespeed-cache: miss
curl -I https://example.com/page
# Second request: cf-cache-status: HIT (or DYNAMIC if uncacheable),
# x-litespeed-cache: hit
For Redis:
redis-cli --no-auth-warning INFO stats | grep keyspace_hits
redis-cli --no-auth-warning DBSIZE
After wp cache flush, DBSIZE on the WP-prefixed keys should drop. keyspace_hits rate goes to zero briefly, then rebuilds.
The fix
The deploy-time invalidation sequence we follow:
- Edge first. Purge Cloudflare via API:
curl -X POST https://api.cloudflare.com/client/v4/zones/<zone>/purge_cache -H "Authorization: Bearer <token>" -d '{"files":["https://example.com/page1"]}'. Wildcard purge for big deploys:{"purge_everything": true}. - Server full-page cache. On the cPanel host:
wp litespeed-purge all(or selectivelywp litespeed-purge tag <tag>). Or via the LSCache plugin’s purge button. - Object cache.
wp cache flushfrom the site root, or per-key deletion viaredis-cli DEL <key>. AvoidFLUSHDBunless the Redis instance is single-tenant; on shared Redis it nukes everyone’s data. - OpCache. If you changed PHP files in-place (no atomic deploy), call
opcache_reset()via a one-off URL or restart PHP-FPM cleanly:whmapi1 restart_service service=apache_php_fpm. - Verify.
curlthe affected URL withCache-Control: no-cacheand confirm fresh content. Then a normalcurlshould show a fresh cache entry repopulated from the new origin.
Document the invalidation steps in the deploy runbook — they are easy to skip when something goes wrong. Stack Harbor builds deploy + invalidation flows as part of deployment management.