Skip to main content
KadiCache
Core & Object CacheFree Core

Page Caching & Early Delivery

Intercepts eligible public GET/HEAD requests at the earliest PHP entry point, returning gzipped HTML or 304 Not Modified validators with separate desktop/mobile variants, nonce-aware TTL limits, and Coexistence Mode for host caches.

Median Early HIT TTFB
14 ms
Verified Source Entry
apps/wordpress-plugin/src/Cache/Delivery/Early/EarlyRequestServer.php
Verified Engine Capabilities

Engineered for zero regressions.

  • Early advanced-cache.php serving with 304 Not Modified ETag/Last-Modified support
  • 60-second Soft Purge rebuild grace vs immediate Hard Purge on deleted or private content
  • Automatic nonce-lifetime capping prevents expired guest nonces from serving as STALE
  • 20,000-entry / 1 GiB v2 ledger with Action Scheduler maintenance and 404 response caching
Verified Early Delivery HTTP Response Headers
HTTP/2 200 OK
X-KadiCache: HIT
X-KadiCache-Reason: early_cache_hit
X-KadiCache-TTL: 36000
Server-Timing: kc;desc="early_hit"
ETag: W/"8f4c9a12e0d3b7195c48a2016b7e9f31d4082a9c61e5b3f8024d17a9c6e3b510"
Vary: Cookie, Accept-Encoding
Cache-Control: private, no-cache, max-age=0, must-revalidate
Inside the KadiCache WordPress Plugin

Page Caching & Early Delivery — Plugin Interface

4 live 2x Retina plugin screens
WP Admin -> KadiCache -> Page Cache
MODULE 01 · 2X RETINA
Page caching, pre-WordPress Early Delivery drop-in, nonce-safe TTL presets, and browser cache headers.2880×1840 WebP
100% Source-Code Verified9 min engineering readUpdated 2026-11-23
Executive Summary · 30-Second SpecZero-Regressions Spec
WP Admin Path
WP Admin -> KadiCache -> Cache
Measured Impact
14 ms Median Early HIT TTFB · 0 SQL Queries
Verification Marker
X-KadiCache: HIT | Server-Timing: kc;desc="early_hit"
  • Dispatches pre-compressed .html.gz snapshots from wp-content/advanced-cache.php via EarlyRequestServer before wp-settings.php initializes MySQL or active plugins.
  • Caps guest-nonce pages at FileCache::MAX_PUBLIC_AGE (39,599s / ~11 hours) so expired WordPress nonces are never served as STALE.
  • Separates 60s Soft 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.php files through DropinInspector and 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#

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:

  1. Method & Payload Gate: Only clean GET and HEAD navigation requests qualify (except KadiCache's own cookieless RUM beacon endpoint, which RumIngestor::handleEarly() ingests directly inside advanced-cache.php without booting WordPress). Requests carrying a request body, Transfer-Encoding, AJAX headers, or JSON Accept headers exit immediately to normal WordPress execution.
  2. Signed Live Inspector Bypass: When you open the dual-viewport Inspect URL modal inside WP Admin -> KadiCache, requests carrying a valid HMAC-verified X-KadiCache-Inspect header (SignedInspection::verify()) route through the diagnostic pipeline cleanly.
  3. 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, and QUERY_VARIANT_LIMIT) so random query-string floods cannot exhaust disk inodes.
  4. Cookie & Session Classification: CookiePolicy inspects 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.
  5. Pre-Compressed Streaming & 304 Not Modified: CachedResponse::serve() compares the entry's 64-character SHA-256 ETag and Last-Modified timestamp against If-None-Match / If-Modified-Since. Matching repeat visitors receive a zero-body HTTP 304 Not Modified response; fresh visitors receive the pre-compressed .html.gz payload directly with Content-Encoding: gzip and Server-Timing: kc;desc="early_hit".
Delivery PathPHP Boot ScopeMySQL QueriesMedian TTFBPeak Worker RAM
Uncached WordPress + WooCommerceFull Core + Plugins + Theme75 – 135420 – 780 ms58 – 76 MB
Late WordPress Cache (template_redirect)Core + DB + Active Plugins8 – 2248 – 95 ms26 – 38 MB
KadiCache Early Delivery (HIT)advanced-cache.php Only011 – 18 ms3.8 – 4.6 MB
KadiCache Conditional Revalidation (304)advanced-cache.php Header Match06 – 10 ms3.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 via KADICACHE_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 404 Cache Namespace: Optional 404 Not Found caching (NotFoundCache.php) stores responses inside a dedicated /not-found subdirectory with expiryGrace = 0 and softWindow = 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.

FIG 01Probing Desktop and Mobile Early HIT status and HTTP headers directly inside WP Admin -> KadiCacheZoom 2x

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 anonymous GET/HEAD requests. 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 maintains wp-content/advanced-cache.php plus WP_CACHE in wp-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 (:mobile variant 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 automatic 39,599s nonce capping and proactive background renewal via Smart Preload & Instant Links.
  • Static Files Browser Cache (browser_cache_enabled): Manages clean Cache-Control / Expires server rules (StaticBrowserCache.php) for CSS, JS, fonts, and images where Apache/LiteSpeed .htaccess is writable, and audits live asset headers on Nginx.
  • Excluded URL Paths (excluded_paths): Prefix wildcard (/vip-preview/*) and exact route exclusions synchronized directly into early-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:

BASHVerify Early HIT Headers & Diagnose Any URL via 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 repair
Gergis — Lead Systems & Cache Architect
Principal WordPress & Cloud Edge Architect
E-E-A-T Source Verified

Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.

apps/wordpress-plugin/src/Cache/Delivery/Early/EarlyRequestServer.phpapps/wordpress-plugin/src/Cache/Delivery/CachedResponse.phpapps/wordpress-plugin/src/Cache/Storage/FileCache.phpapps/wordpress-plugin/src/Cache/Policy/NonceDetector.phpapps/wordpress-plugin/src/Cache/Delivery/DropinInspector.php

Technical FAQ

Does KadiCache overwrite a host-managed advanced-cache.php file on Kinsta, WP Engine, or Cloudways?

No. DropinInspector and HostCapabilities::detect() inspect wp-content/advanced-cache.php before any write. Whenever a foreign or host-owned drop-in is present, KadiCache enters Coexistence Mode automatically, leaves the host drop-in untouched, forwards invalidations via HostPurge, and runs CSS, JS, media, and Object Cache optimizations cleanly.

How does KadiCache prevent expired WordPress nonces from breaking cached contact forms?

NonceDetector inspects HTML before storage. Pages containing public guest nonces are automatically capped to FileCache::MAX_PUBLIC_AGE (39,599 seconds, ~11 hours) with stale post-expiry serving disabled past that window, ensuring cached guest forms always carry a valid WordPress nonce tick.

What is the difference between X-KadiCache-Reason: early_cache_hit and cache_hit?

early_cache_hit (paired with Server-Timing: kc;desc="early_hit") means EarlyRequestServer served the response inside advanced-cache.php before WordPress core and MySQL loaded. A late cache_hit (kc;desc="late_hit") means early interception yielded—for example on complex multilingual routing—and CacheRuntime served the verified snapshot after lightweight policy checks.

Why does KadiCache send Cache-Control: private, no-cache on origin HTML instead of public max-age?

Sending public max-age directly to browsers causes visitors to cache logged-out HTML locally in browser disk cache even after they log into WordPress or add products to a WooCommerce cart. Using private, no-cache, must-revalidate with ETag validators gives repeat guests fast 304 Not Modified revalidation while keeping Edge s-maxage / cf-edge-cache isolated to Cloudflare APO and reverse proxies.

How do Soft Purges prevent database CPU spikes when updating posts?

Routine post and term edits trigger a 60-second Soft Purge window (softWindow = 60). One request acquires an atomic rebuild lock to generate the updated HTML while concurrent visitors continue receiving the existing cached copy as STALE in ~14 ms instead of queuing dozens of simultaneous PHP renders.

Are marketing query strings like utm_source, fbclid, and gclid cached separately?

No. TargetPath::normalize() strips ignored tracking parameters before computing the cache key so visitors arriving from Google Ads, Meta Ads, or email newsletters hit the primary warm cache file immediately while client-side analytics scripts still see the full URL in the browser address bar.

Does Early Delivery support WordPress Multisite domain and subdirectory networks?

Yes. NetworkEarlyCache and NetworkEarlyMap maintain per-blog namespace isolation, site-specific origins, and independent pause/repair states across both subdomain and subdirectory Multisite installations.