- Dispatches pre-compressed
.html.gzsnapshots fromwp-content/advanced-cache.phpviaEarlyRequestServerbeforewp-settings.phpinitializes MySQL or active plugins. - Caps guest-nonce pages at
FileCache::MAX_PUBLIC_AGE(39,599s/ ~11 hours) so expired WordPress nonces are never served asSTALE. - Separates
60sSoft Purge grace windows during Routine Post Updates from immediate Hard Purges when content is unpublished, password-protected, or deleted. - Detects foreign or host-managed
advanced-cache.phpfiles throughDropinInspectorand enters Coexistence Mode automatically without overwriting host files.
Table of Contents (6 sections)
- Why Uncached WordPress Boots Cost 350 ms to 900 ms of Server Wait Time
- Inside EarlyRequestServer.php: Guarded Pre-WordPress Execution
- Soft Purge (60s) vs Hard Purge: Eliminating Post-Update Stampedes
- Nonce-Aware TTL Capping & Security Header Fidelity
- Navigating the Cache Controls Inside WP Admin -> KadiCache
- Verifying Early Delivery via HTTP Headers & WP-CLI
Why Uncached WordPress Boots Cost 350 ms to 900 ms of Server Wait Time#
Every uncached request to a standard WordPress + WooCommerce installation forces PHP-FPM to repeat an expensive boot sequence before sending a single byte of HTML. After wp-config.php executes, wp-settings.php loads core libraries, opens a MySQL or MariaDB TCP socket, deserializes autoloaded rows from wp_options, instantiates every active plugin, registers hundreds of rewrite rules and block patterns, compiles Elementor or Gutenberg templates, and runs theme hooks. On a typical commercial WooCommerce catalog with 25 active plugins, that server-side work consumes 45 MB to 78 MB of PHP memory, executes 70 to 140 SQL queries, and holds Time to First Byte (TTFB) above 420 ms even on modern NVMe VPS hardware.
Many legacy WordPress caching plugins still rely on late output buffering registered on template_redirect or init, or write fragile .htaccess rewrite blocks that bypass PHP entirely without understanding dynamic cookies, security headers, or expired WordPress nonces. Late PHP caching wastes CPU cycles because WordPress and MySQL have already booted; blind .htaccess static rules risk serving cached guest pages to shoppers who just added an item to their cart, stripping runtime Content-Security-Policy headers, or breaking AJAX contact forms after 12 hours when WordPress nonce ticks rotate.
KadiCache solves both sides of that trade-off by executing a self-contained, dependency-free PHP gatekeeper inside wp-content/advanced-cache.php. When WP_CACHE is true, WordPress invokes advanced-cache.php near the top of wp-settings.php — before opening a database connection, before loading mu-plugins, and before initializing any plugin or theme code.
Inside EarlyRequestServer.php: Guarded Pre-WordPress Execution#
Because advanced-cache.php runs before WordPress options exist in memory, EarlyRequestServer reads a compact, atomically published configuration snapshot at early-config.php inside KadiCache's owned cache root. Every snapshot begins with an executable exit guard (<?php exit; ?>\n), is written via temporary file + LOCK_EX + chmod(0600) + atomic rename(), and carries a strict SNAPSHOT_LIFETIME ceiling of 86,400 seconds.
Once the snapshot passes integrity verification, EarlyRequestServer runs a deterministic eligibility pipeline in under a millisecond:
- Method & Payload Gate: Only clean
GETandHEADnavigation requests qualify (except KadiCache's own cookieless RUM beacon endpoint, whichRumIngestor::handleEarly()ingests directly insideadvanced-cache.phpwithout booting WordPress). Requests carrying a request body,Transfer-Encoding, AJAX headers, or JSONAcceptheaders exit immediately to normal WordPress execution. - Signed Live Inspector Bypass: When you open the dual-viewport Inspect URL modal inside
WP Admin -> KadiCache, requests carrying a valid HMAC-verifiedX-KadiCache-Inspectheader (SignedInspection::verify()) route through the diagnostic pipeline cleanly. - Query String Normalization & Bounds:
TargetPath::normalize()strips marketing noise parameters (utm_*,fbclid,gclid,msclkid) so paid ad traffic shares the exact same warm cache entry as organic visitors, while enforcing strict upper bounds (QUERY_PARAMETER_LIMIT,QUERY_VALUE_BYTES, andQUERY_VARIANT_LIMIT) so random query-string floods cannot exhaust disk inodes. - Cookie & Session Classification:
CookiePolicyinspects raw cookie names against logged-in WordPress cookies (wordpress_logged_in_*), password-protected post cookies (wp-postpass_*), active PHP sessions (PHPSESSID), WooCommerce session/cart risk rules (WooCommerceSession), currency transition flags (Curcy::transitionPending()), and custom bypass rules. - Pre-Compressed Streaming &
304 Not Modified:CachedResponse::serve()compares the entry's 64-character SHA-256ETagandLast-Modifiedtimestamp againstIf-None-Match/If-Modified-Since. Matching repeat visitors receive a zero-bodyHTTP 304 Not Modifiedresponse; fresh visitors receive the pre-compressed.html.gzpayload directly withContent-Encoding: gzipandServer-Timing: kc;desc="early_hit".
| Delivery Path | PHP Boot Scope | MySQL Queries | Median TTFB | Peak Worker RAM |
|---|---|---|---|---|
| Uncached WordPress + WooCommerce | Full Core + Plugins + Theme | 75 – 135 | 420 – 780 ms | 58 – 76 MB |
Late WordPress Cache (template_redirect) | Core + DB + Active Plugins | 8 – 22 | 48 – 95 ms | 26 – 38 MB |
KadiCache Early Delivery (HIT) | advanced-cache.php Only | 0 | 11 – 18 ms | 3.8 – 4.6 MB |
KadiCache Conditional Revalidation (304) | advanced-cache.php Header Match | 0 | 6 – 10 ms | 3.8 MB |
Soft Purge (60s) vs Hard Purge: Eliminating Post-Update Stampedes#
A subtle flaw in conventional WordPress cache plugins appears the moment an editor clicks Update on a high-traffic article or WooCommerce product. Deleting cached files immediately causes a cache stampede: if 40 concurrent visitors request the homepage during the 600 milliseconds it takes PHP to regenerate the page, all 40 requests miss the cache simultaneously and hammer MySQL in parallel.
FileCache.php prevents stampedes by separating Soft Purges from Hard Purges, backed by per-entry generation tokens and lease locks in StorageIo:
- Soft Purge (
softWindow = 60s, configurable viaKADICACHE_CACHE_SOFT_PURGE_WINDOW) & Expiry Grace (expiryGrace = 600s,KADICACHE_CACHE_EXPIRY_GRACE): When a published post, term, or menu is edited, KadiCache marks affected URLs soft-expired rather than deleting the bytes on disk. The first eligible background worker or visitor acquires an atomic rebuild lease to render fresh HTML, while concurrent visitors during that brief window receive the existing snapshot (X-KadiCache: STALE) in ~14 ms with zero database pile-up. - Immediate Hard Purge: When a post transitions to
draft,private,trash, or gains a post password, or when an administrator triggers Purge All, KadiCache executes a Hard Purge. Stale serving is forbidden immediately so unpublished, deleted, or restricted content can never leak for even one second. - Isolated
404Cache Namespace: Optional404 Not Foundcaching (NotFoundCache.php) stores responses inside a dedicated/not-foundsubdirectory withexpiryGrace = 0andsoftWindow = 0, absorbing broken bot crawls without letting a newly published slug serve a stale 404.
Nonce-Aware TTL Capping & Security Header Fidelity#
Public WordPress pages frequently embed guest nonces inside comment forms, Contact Form 7 / WPForms payloads, or public AJAX widgets. Standard WordPress nonces rotate every 12 hours and remain valid for up to 24 hours. Setting a naive 7-day HTML cache TTL breaks every form on the site after the first day.
NonceDetector.php scans captured HTML before publication into FileCache. Whenever a public guest nonce is detected, CacheEntryCodec automatically caps that entry's maximum public age to FileCache::MAX_PUBLIC_AGE (39,599 seconds, just under 11 hours) and disables post-expiry stale grace past the nonce boundary. Even if your global Cache Lifetime in WP Admin -> KadiCache -> Cache is set to 48h or 7d, nonce-bearing pages refresh automatically inside WordPress's valid tick window (and emit X-KadiCache-TTL-Reason: nonce_ttl_cap when WP_DEBUG is enabled). Conversely, if a plugin prints a session-bound private nonce, KadiCache blocks shared publication altogether.
Equally important, CachedResponse::securityMatches() captures and replays security-critical HTTP headers (Content-Security-Policy, X-Frame-Options, Cross-Origin-*, Permissions-Policy, Strict-Transport-Security). On late fallback hits, if a security plugin dynamically alters response headers on the current request so they no longer match the stored snapshot, CachedResponse refuses to overwrite the new security policy and renders fresh HTML instead.
Navigating the Cache Controls Inside WP Admin -> KadiCache#
Every Page Cache control in WP Admin -> KadiCache -> Cache maps directly to a deterministic runtime setting in Settings.php:
- Enable Page Caching (
enabled): Activates HTML capture and serving for anonymousGET/HEADrequests. Turning Page Caching off preserves independent front-end optimizations (such as Delay JS, Lazyload, or Cloud Pro RUCSS) when an upstream proxy handles HTML caching. - Serve Before WordPress Loads (
early_cache_enabled): Installs and maintainswp-content/advanced-cache.phpplusWP_CACHEinwp-config.php. Includes the Drop-in Details & Recovery drawer showing live ownership status and 1-click repair. - Separate Cache Files for Mobile (
mobile_cache_enabled): Maintains isolated Desktop and Mobile cache buckets (:mobilevariant hash). Leave off on responsive CSS themes so mobile and desktop visitors share higher hit ratios; enable only when PHP hooks (wp_is_mobile()) output different server-side HTML markup. - Cache Lifetime (
cache_lifetime_value/cache_lifetime_unit): Quick presets (10h,24h,48h,7d, or custom) paired with automatic39,599snonce capping and proactive background renewal via Smart Preload & Instant Links. - Static Files Browser Cache (
browser_cache_enabled): Manages cleanCache-Control/Expiresserver rules (StaticBrowserCache.php) for CSS, JS, fonts, and images where Apache/LiteSpeed.htaccessis writable, and audits live asset headers on Nginx. - Excluded URL Paths (
excluded_paths): Prefix wildcard (/vip-preview/*) and exact route exclusions synchronized directly intoearly-config.php, alongside per-post checkboxes in the Gutenberg Document Sidebar (EditorSettings.php).
Verifying Early Delivery via HTTP Headers & WP-CLI#
You can verify Early Delivery in under 15 seconds from either the built-in Inspect URL modal inside WP Admin -> KadiCache, curl in a logged-out terminal, or CacheCli.php in WP-CLI:
# 1. Prime on first request, confirm Early HIT on second request
curl -sI https://example.com/ | grep -iE "^(x-kadicache|server-timing|etag|cache-control)"
# 2. Machine-readable site cache, drop-in owner, storage & 24h visit stats
wp kadicache status --format=json
# 3. Deep single-URL eligibility & header inspection
wp kadicache diagnose https://example.com/shop/ --format=json
# 4. Targeted URL purge, full site purge, or self-healing bootstrap repair
wp kadicache purge https://example.com/pricing/
wp kadicache purge --all
wp kadicache repairCreator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.