Page Caching, Early advanced-cache.php Delivery & Soft Purge
Master EarlyRequestServer.php pre-WordPress delivery, 60-second Soft Purge stampede protection vs Hard Purges, 39,599s nonce TTL capping, and 304 ETag revalidation.
- Serves pre-compressed
.html.gzsnapshots straight fromwp-content/advanced-cache.php(EarlyRequestServer.php) beforewp-settings.phpinitializes MySQL or plugins. - Prevents post-update database stampedes via
60sSoft Purge grace windows while enforcing immediate Hard Purges when content becomes draft, private, trashed, or password-protected. - Scans HTML via
NonceDetector.phpand caps guest-nonce pages toFileCache::MAX_PUBLIC_AGE(39,599s/ ~11 hours) so cached forms never submit expired WordPress nonces. - Supports conditional
HTTP 304 Not Modifiedrevalidation (ETag+Last-Modified), static asset browser cache headers (StaticBrowserCache.php), and isolated404caching (NotFoundCache.php).
How EarlyRequestServer.php Serves Cached HTML Before WordPress Boots#
When define('WP_CACHE', true) is active in wp-config.php, WordPress core includes wp-content/advanced-cache.php near the top of wp-settings.php—before connecting to MySQL, before loading wp_options, and before executing a single plugin or theme file. KadiCache places a lightweight, zero-dependency execution gate (EarlyRequestServer.php) at that exact point.
Because WordPress database options are not loaded yet during advanced-cache.php, KadiCache compiles your active cache rules into an atomically written PHP snapshot (early-config.php, guarded by <?php exit; ?>, 0600 file permissions, SNAPSHOT_LIFETIME = 86,400s, and live file-fingerprint checks via EarlySnapshotFiles::unchanged()). On every incoming GET or HEAD request:
- Request & Method Hygiene: Requests with POST bodies,
Transfer-Encoding, XMLHttpRequest/JSON headers, or admin paths exit immediately to standard WordPress. - Path & Query Normalization (
TargetPath.php): Strips marketing tracking noise (utm_*,fbclid,gclid) while enforcing strict query-parameter limits so ad clicks hit the canonical warm cache file. - Cookie & Session Policy (
CookiePolicy.php): Evaluates logged-in cookies, password-protected post cookies (wp-postpass_*), WooCommerce cart/checkout/currency states, and custom bypass rules. - Conditional
304or Streamed.html.gzDispatch (CachedResponse.php): If the visitor’sIf-None-Matchheader matches the entry’s 64-hex SHA-256ETag, KadiCache returns an instant zero-bodyHTTP 304 Not Modified(~7 ms). Otherwise, it streams the pre-compressed.html.gzfile directly (X-KadiCache: HIT,Server-Timing: kc;desc="early_hit").
Reference Guide to Every Control in WP Admin -> KadiCache -> Cache#
| Control Name | Setting Key | Recommended Setting | Operational Behavior |
|---|---|---|---|
| Enable Page Caching | enabled | ON | Captures and serves public anonymous GET/HEAD HTML responses |
| Serve Before WordPress Loads | early_cache_enabled | ON | Activates advanced-cache.php pre-DB interception (~14 ms TTFB) |
| Separate Cache Files for Mobile | mobile_cache_enabled | OFF on responsive CSS themes | Creates separate :mobile bucket only when PHP outputs mobile-specific HTML (wp_is_mobile()) |
| Cache Lifetime (TTL) | cache_lifetime_value / unit | 24h – 48h (10h on dynamic sites) | Freshness ceiling paired with automatic 39,599s guest-nonce capping |
| Static Files Browser Cache | browser_cache_enabled | ON (where .htaccess active) | Writes 1-year Cache-Control / Expires rules for CSS, JS, fonts & images (StaticBrowserCache.php) |
| Excluded URL Paths | excluded_paths | Custom dynamic routes only | Exact paths (/portal/) or prefix wildcards (/account/*) synced to early-config.php |
Soft Purge (60s) vs Hard Purge: Zero Stampedes, Zero Private Leaks#
Deleting cached files synchronously the instant an editor updates a busy homepage causes 30+ concurrent visitors to miss cache at the exact same millisecond and overload MySQL. FileCache.php eliminates cache stampedes by distinguishing between Soft Purges and Hard Purges:
- Routine Content Updates -> Soft Purge (
softWindow = 60s, Expiry Grace600s): Editing a published post, product price, category, or navigation menu marks affected cache entries soft-expired. A single worker acquires an atomic rebuild lease (StorageIo) to render fresh HTML in the background while concurrent visitors receive the existing snapshot (X-KadiCache: STALE) in ~14 ms with zero database contention. (Advanced operators can tuneKADICACHE_CACHE_SOFT_PURGE_WINDOWandKADICACHE_CACHE_EXPIRY_GRACEinwp-config.php.) - Visibility Restrictions & Manual Clear -> Immediate Hard Purge: Changing a post to
draft,private,pending,trash, adding a post password, or clicking Purge All triggers an immediate Hard Purge—forbiddingSTALEserving instantly so restricted content never leaks.
Automatic WordPress Nonce Protection (NonceDetector.php) & 404 Isolation#
Contact forms (Contact Form 7, WPForms, Gravity Forms, Elementor Forms) and public AJAX widgets frequently embed guest WordPress nonces inside HTML. Because WordPress nonces expire after 12–24 hours, a naive 7-day cache TTL breaks form submissions on day two!
NonceDetector.php inspects HTML before storage: whenever a public guest nonce is present, KadiCache automatically caps that page’s maximum public age at FileCache::MAX_PUBLIC_AGE = 39,599 seconds (~11 hours) and disables stale serving past that ceiling—even if your global TTL is 7 days! Meanwhile, optional 404 Response Caching (WP Admin -> KadiCache -> Tools -> Proxy, 404 & Hints, NotFoundCache.php) isolates 404 Not Found snapshots in a dedicated /not-found namespace with zero stale grace so broken bot crawls stop hitting MySQL without ever shadowing a newly published post.
# Check live drop-in state, early readiness, cached file count & 24h hit ratio
wp kadicache status --format=json
# Purge a single URL or the entire site cache
wp kadicache purge https://example.com/pricing/
wp kadicache purge --all
# Self-heal advanced-cache.php, WP_CACHE & early-config.php snapshots
wp kadicache repairChoosing the Optimal Cache Lifetime (TTL) by Website Type#
Inside WP Admin -> KadiCache -> Cache, select your Cache Lifetime preset based on how frequently unauthenticated content changes outside WordPress hooks:
- Blogs, Corporate Sites & SaaS Marketing Portals (
48h–7d): Because publishing or editing a post, page, category, or menu automatically triggers a targeted Soft Purge (ContentInvalidation.php&PublicationPurge.php), static editorial sites safely enjoy multi-day cache lifetimes whileNonceDetector.phpstill refreshes guest-form pages automatically every< 11 hours. - WooCommerce Stores With Live Inventory & Sale Schedules (
10h–24h):CommerceStockTracker.phpinvalidates product and archive snapshots automatically whenever stock status transitions (instock<->outofstock), prices change, or orders decrement the final unit; pairing a24hTTL with Sitemap Preload keeps catalog hit ratios above96%. - Sites Pulling External Unhooked APIs in PHP (
1h–6h): If a custom template fetches live weather, stock tickers, or external CRM feeds directly in PHP without firing WordPress save hooks, use a shorter TTL or load that dynamic widget asynchronously via REST/fetch.
Frequently Asked Operational Questions
Can I set my Cache Lifetime to 7 days without breaking Contact Form 7 or WPForms?
What happens if I update a plugin via SFTP or Git without clicking Purge All in WP Admin?
Does disabling Serve Before WordPress Loads turn off Page Caching completely?
How do I enable 404 Not Found page caching to stop bot crawls from hitting MySQL?
Does KadiCache clean up .htaccess browser-cache rules cleanly if deactivated?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.