This article is for WordPress sites that run the LiteSpeed Cache plugin (LSCWP) on a LiteSpeed server and also sit behind Cloudflare. That setup gives you two caches: LiteSpeed keeps ready-made pages on your server, and Cloudflare keeps copies in data centres close to your visitors. When the two agree, pages load fast and PHP rarely runs. When they disagree, visitors see an old version of a page after you publish, or a logged-in page leaks into the public cache. The fix is to give each cache a clear job, set matching cache lifetimes, and connect the purge so that clearing one also clears the other.
How to verify
# Check which cache layer served a response
curl -sI https://example.com/sample-page/ | grep -i 'cf-cache-status\|x-litespeed-cache\|age'
# CF-Cache-Status: HIT means Cloudflare served it
# X-LiteSpeed-Cache: hit means LSWS origin cache served it
# Age: N means the response has been in cache for N seconds
# Confirm Cloudflare is proxying (orange cloud)
curl -sI https://example.com/ | grep 'Server\|cf-ray'
# Check LSCWP Cloudflare API credentials
wp eval 'print_r(get_option("litespeed.conf.cdn-cloudflare_email"));'
wp eval 'print_r(get_option("litespeed.conf.cdn-cloudflare_key"));'
# Test a manual purge from WP-CLI
wp litespeed-purge all
# Verify Cloudflare is not caching your wp-admin
curl -sI https://example.com/wp-admin/ | grep 'CF-Cache-Status'
What’s happening
When a visitor requests a page, the request first hits Cloudflare’s edge. If Cloudflare has a cached copy and it is within TTL, Cloudflare serves it without touching your origin at all — CF-Cache-Status: HIT. If Cloudflare does not have it or the TTL has expired, Cloudflare forwards the request to your LSWS origin. LSWS then checks its own cache: if it has a valid cached copy, it serves it and responds to Cloudflare — which then caches the response for subsequent requests from its edge. Only on a double-miss — nothing at Cloudflare and nothing in LSWS cache — does the request reach PHP.
The coordination problem arises from the Cache-Control headers that LSCWP sets. LSCWP uses Cache-Control: public, max-age=N for cacheable pages and Cache-Control: no-cache, no-store for excluded pages. Cloudflare by default respects these headers. The conflict happens when:
-
Cloudflare’s default edge TTL overrides the origin’s
max-age. Cloudflare has an Edge Cache TTL setting that, if set to a fixed value in a Cache Rule, will ignore the origin’smax-ageand use its own value. A page LSCWP wants to cache for 1 hour may be kept at Cloudflare for 4 hours or 4 days depending on your Cloudflare plan settings. -
Cloudflare caches a page LSCWP intended as private. If your Cloudflare Cache Rule says “cache everything,” it will cache a response even if LSCWP sent
Cache-Control: private. This can expose logged-in user sessions to anonymous visitors. -
A WordPress content update clears LSWS cache but leaves Cloudflare stale. When you publish a post, LSCWP purges the relevant pages from its own cache. Unless it is also configured to call the Cloudflare API, the old version remains at the Cloudflare edge until its TTL expires.
The correct setup treats LSWS as the source of truth for cache policy and Cloudflare as a pure CDN for static assets, with a purge connection between them.
The procedure
Step 1 — Configure Cloudflare to respect origin cache headers.
In Cloudflare Dashboard, go to Caching → Configuration:
- Set Browser Cache TTL to Respect Existing Headers
- Set Caching Level to Standard
Under Cache Rules, ensure there is no rule set to “Cache Everything” that would override no-cache headers from your origin. If you need aggressive Cloudflare caching, build a Cache Rule scoped to specific static asset paths (*.css, *.js, *.jpg) rather than all URLs.
Step 2 — Create bypass rules for WordPress dynamic paths.
In Cloudflare, create a Cache Rule with Bypass Cache for:
URI Path starts with /wp-admin
URI Path starts with /wp-login.php
URI Path starts with /cart
URI Path starts with /checkout
URI Path starts with /my-account
Cookie contains wordpress_logged_in
Cookie contains woocommerce_items_in_cart
These ensure that admin, logged-in, and transactional requests never get a Cloudflare cache hit.
Step 3 — Connect LSCWP to Cloudflare API for purge coordination.
In WP Admin, go to LiteSpeed Cache → CDN → Cloudflare. Enter:
- Email: your Cloudflare account email
- API Key: your Cloudflare Global API Key (or create a scoped API Token with
Cache Purgepermission for your zone) - Zone ID: found in your Cloudflare dashboard under the domain overview
Save. LSCWP will now call the Cloudflare API to purge specific URLs whenever it purges them from its own cache. A post publish fires a purge at LSWS and immediately follows with a Cloudflare purge of the same URL.
Step 4 — Set Cloudflare Browser Cache TTL for static assets.
Go to Cloudflare → Caching → Cache Rules and create a rule for static assets:
- Condition:
URI Path matches regex \.(css|js|jpg|jpeg|png|gif|webp|woff2|svg)$ - Cache TTL: 1 month (2,592,000 seconds)
- Browser Cache TTL: 1 day
For HTML pages, let the origin Cache-Control header control TTL (Respect Existing Headers setting from Step 1).
Step 5 — Verify the two-layer cache is working.
# First request: LSWS primes its cache, Cloudflare gets a MISS
curl -sI https://example.com/sample-page/ | grep -E 'cf-cache-status|x-litespeed-cache|age'
# Second request from a different IP/PoP should show CF HIT
# (You can use Cloudflare's cache checker at dash.cloudflare.com → Caching → Cache Checker)
# Confirm purge fires both layers when you update a post in WP Admin
# Check the LSCWP log after saving a post:
tail -20 /usr/local/lsws/Example/html/wp-content/debug.log | grep -i 'litespeed\|cloudflare\|purge'
Common pitfalls
Cloudflare serving stale pages hours after a WordPress update. This means LSCWP is not calling the Cloudflare API on purge. Check the LSCWP CDN Cloudflare settings and confirm the API credentials are valid. A common cause is an API Token (not Global API Key) that lacks the Cache Purge permission on the correct zone.
CF-Cache-Status: DYNAMIC on pages that should be cached. Cloudflare uses DYNAMIC for responses it decided not to cache, usually because the origin sent Cache-Control: no-cache or Set-Cookie. If your WordPress pages are all returning DYNAMIC, check that LSCWP is generating correct Cache-Control: public headers — run curl -sI https://example.com/sample-page/ and inspect the response headers before they hit Cloudflare (use --resolve to bypass Cloudflare and hit the origin IP directly).
Double-caching increasing TTFB instead of reducing it. If Cloudflare is configured to cache HTML AND you have Cloudflare Tiered Cache or Argo, requests that miss all Cloudflare PoPs cascade to origin. Adding Cloudflare origin cache pull latency on top of LSWS origin cache hit adds one round-trip for no benefit. Ensure your Cloudflare Cache Rule for HTML pages uses Respect Existing Headers so Cloudflare honors LSCWP’s TTLs.
Cloudflare Polish or Mirage conflicting with LSWS image optimization. If you have both LSWS/LSCWP image optimization and Cloudflare Polish enabled, images may be double-processed. Disable one. LSCWP’s image optimization runs at WordPress/PHP level and generates WebP; Cloudflare Polish runs at the CDN edge. Use one, not both.
ESI holes being cached by Cloudflare. If you use LSCWP ESI, the page body contains <esi:include> tags that LSWS assembles on the way out. If Cloudflare caches a response before LSWS has assembled the ESI tags, Cloudflare will serve raw <esi:include> tags to browsers. Ensure all pages using ESI are not cached at Cloudflare level — set a Cloudflare Cache Rule to Bypass for those paths, and let LSWS handle the full caching and ESI assembly.
Two-layer cache setups between LSWS and Cloudflare require coordinated configuration on both sides — a single misconfigured rule can negate the performance work on the other. Stack Harbor’s managed operations team configures and validates Cloudflare and LSCWP together as a single end-to-end cache layer during every site handoff.