Skip to main content
KadiCache
Browse 37 Docs Guides & Search

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.

Cache/Delivery/Early/EarlyRequestServer.phpCache/Storage/FileCache.phpCache/Policy/NonceDetector.phpCache/Delivery/StaticBrowserCache.php
WP Admin -> KadiCache -> Page Cache
MODULE 07 · 2X RETINA
Page caching, pre-WordPress Early Delivery drop-in, nonce-safe TTL presets, and browser cache headers.2880×1840 WebP
Quick Summary · 30-Second Operational SpecSource-Verified Guide
WP Admin Path
WP Admin -> KadiCache -> Cache
Expected Outcome
11–18 ms Early HIT TTFB · 39,599s Nonce Guard
Key Marker / Engine
EarlyRequestServer.php | FileCache.php | NonceDetector.php
  • Serves pre-compressed .html.gz snapshots straight from wp-content/advanced-cache.php (EarlyRequestServer.php) before wp-settings.php initializes MySQL or plugins.
  • Prevents post-update database stampedes via 60s Soft Purge grace windows while enforcing immediate Hard Purges when content becomes draft, private, trashed, or password-protected.
  • Scans HTML via NonceDetector.php and caps guest-nonce pages to FileCache::MAX_PUBLIC_AGE (39,599s / ~11 hours) so cached forms never submit expired WordPress nonces.
  • Supports conditional HTTP 304 Not Modified revalidation (ETag + Last-Modified), static asset browser cache headers (StaticBrowserCache.php), and isolated 404 caching (NotFoundCache.php).
EarlyRequestServer.php dispatches pre-compressed .html.gz snapshots and 304 Not Modified validators from advanced-cache.php with 0 SQL queries.Click to zoom

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:

  1. Request & Method Hygiene: Requests with POST bodies, Transfer-Encoding, XMLHttpRequest/JSON headers, or admin paths exit immediately to standard WordPress.
  2. 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.
  3. Cookie & Session Policy (CookiePolicy.php): Evaluates logged-in cookies, password-protected post cookies (wp-postpass_*), WooCommerce cart/checkout/currency states, and custom bypass rules.
  4. Conditional 304 or Streamed .html.gz Dispatch (CachedResponse.php): If the visitor’s If-None-Match header matches the entry’s 64-hex SHA-256 ETag, KadiCache returns an instant zero-body HTTP 304 Not Modified (~7 ms). Otherwise, it streams the pre-compressed .html.gz file directly (X-KadiCache: HIT, Server-Timing: kc;desc="early_hit").
FIG 01Configuring Enable Page Caching, Serve Before WordPress Loads, Mobile Cache, Cache Lifetime presets, and Static Browser Cache inside WP Admin -> KadiCacheZoom 2x

Reference Guide to Every Control in WP Admin -> KadiCache -> Cache#

Control NameSetting KeyRecommended SettingOperational Behavior
Enable Page CachingenabledONCaptures and serves public anonymous GET/HEAD HTML responses
Serve Before WordPress Loadsearly_cache_enabledONActivates advanced-cache.php pre-DB interception (~14 ms TTFB)
Separate Cache Files for Mobilemobile_cache_enabledOFF on responsive CSS themesCreates separate :mobile bucket only when PHP outputs mobile-specific HTML (wp_is_mobile())
Cache Lifetime (TTL)cache_lifetime_value / unit24h – 48h (10h on dynamic sites)Freshness ceiling paired with automatic 39,599s guest-nonce capping
Static Files Browser Cachebrowser_cache_enabledON (where .htaccess active)Writes 1-year Cache-Control / Expires rules for CSS, JS, fonts & images (StaticBrowserCache.php)
Excluded URL Pathsexcluded_pathsCustom dynamic routes onlyExact 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 Grace 600s): 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 tune KADICACHE_CACHE_SOFT_PURGE_WINDOW and KADICACHE_CACHE_EXPIRY_GRACE in wp-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—forbidding STALE serving 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.

BASHManage & Inspect Early Page Cache via WP-CLI (CacheCli.php)
# 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 repair

Choosing 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 while NonceDetector.php still refreshes guest-form pages automatically every < 11 hours.
  • WooCommerce Stores With Live Inventory & Sale Schedules (10h – 24h): CommerceStockTracker.php invalidates product and archive snapshots automatically whenever stock status transitions (instock <-> outofstock), prices change, or orders decrement the final unit; pairing a 24h TTL with Sitemap Preload keeps catalog hit ratios above 96%.
  • 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?
Yes! NonceDetector.php scans every cached page automatically. Static brochure and blog pages without nonces stay cached for the full 7 days, while any page containing a guest WordPress nonce is automatically capped at 39,599 seconds (~11 hours) and refreshed cleanly via background preload.
What happens if I update a plugin via SFTP or Git without clicking Purge All in WP Admin?
EarlyRequestServer.php verifies Plugin::VERSION and file fingerprints (EarlySnapshotFiles::unchanged()) before serving from early-config.php, and UpgradeInvalidation.php refreshes cache state automatically as soon as WordPress runs.
Does disabling Serve Before WordPress Loads turn off Page Caching completely?
No. If Serve Before WordPress Loads is turned off (or yielded in Coexistence Mode), KadiCache can still serve verified cached snapshots through its late WordPress runtime layer while executing early WordPress hooks.
How do I enable 404 Not Found page caching to stop bot crawls from hitting MySQL?
Navigate to WP Admin -> KadiCache -> Tools -> Proxy, 404 & Hints and enable Bounded 404 Response Caching. NotFoundCache.php stores 404 snapshots in an isolated namespace with zero stale grace so publishing a new page at that URL works immediately.
Does KadiCache clean up .htaccess browser-cache rules cleanly if deactivated?
Yes. StaticBrowserCache.php and RewriteRuleCleanup.php wrap KadiCache marker blocks cleanly and remove them non-destructively upon feature disablement or plugin uninstallation.
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/Storage/FileCache.phpapps/wordpress-plugin/src/Cache/Policy/NonceDetector.phpapps/wordpress-plugin/src/Cache/Delivery/StaticBrowserCache.php
Was this engineering guide helpful?