includes/Cache/class-cache-invalidator.php
Cache invalidation/purge service — invalidation policy, deletion mechanics, purge-fallback serving, and LiteSpeed swap purge.
Class Cache_Invalidator
Class Cache_Invalidator
final class Cache_InvalidatorConstants
| Constant | Visibility | Value | Line |
|---|---|---|---|
PURGE_FALLBACK_MAX_FILES | public | 25 | 113 |
PURGE_FALLBACK_MAX_DEPTH | public | 6 | 114 |
PURGE_FALLBACK_MAX_BYTES | public | 512 * 1024 | 115 |
PURGE_FALLBACK_MAX_DIRS | public | 200 | 116 |
PURGE_FALLBACK_MAX_TOTAL_BYTES | public | 2 * 1024 * 1024 | 118 |
PURGE_FALLBACK_REDIRECT_STATUS | public | 302 | 120 |
PURGE_FALLBACK_NAMES | public | array( \'fallback.css\', \'fallback.js\', \'fallback.mobile.css\', \'fallback.desktop.css\', \'fallback.mobile.js\', \'fallback.desktop.js\' ) | 123 |
Properties
| Property | Visibility | Type | Default | Line |
|---|---|---|---|---|
$cache | private | Cache | — | 88 |
public __construct()
public function __construct(Cache $cache)Constructor. Parameter Type Default Description $cacheCache— Cache instance (state + storage/policy owner).
public invalidate_dynamic_static_html()
public function invalidate_dynamic_static_html($page_id): voidInvalidate dynamic static HTML cache for a specific page and global archives. Parameter Type Default Description $page_idint— The page ID.
Return: void.
public invalidate_single_static_html()
public function invalidate_single_static_html(int $page_id, bool=true $bump_stats): voidInvalidate the static HTML cache for a single post URL only. Parameter Type Default Description $page_idint— Post ID whose single URL cache must be purged. $bump_statsbool=true— Whether to bump dashboard stats (6x transient deletes + option write). Default true.
Return: void.
public invalidate_woo_object()
public function invalidate_woo_object(int $object_id, string $kind): voidSurgically invalidate cache for a WooCommerce product, order, or coupon. Parameter Type Default Description $object_idint— Woo object (product/order/coupon) ID. $kindstring— Object kind: \’product\’, \’order\’, or \’coupon\’.
Return: void.
publicstatic get_purge_fallback_path()
public static function get_purge_fallback_path(string $file_path): stringMap a derived asset path to its sibling last-good fallback path. Parameter Type Default Description $file_pathstring— Absolute derived-asset path.
Return: string — Sibling fallback path, or \’\’ when not applicable.
public retain_purge_fallback()
public function retain_purge_fallback(string $file_path): voidRetain a last-good fallback copy before a derived file is purged. Parameter Type Default Description $file_pathstring— The derived file about to be deleted.
Return: void.
public get_purge_fallback_response()
public function get_purge_fallback_response(string $requested_path): arrayResolve a post-purge miss under the cache path to its fallback. Parameter Type Default Description $requested_pathstring— Absolute requested derived-asset path.
Return: array{served: — bool, status: int, fallback_path: string, location: string} Resolution.
publicstatic purge_fallback_redirect_status()
public static function purge_fallback_redirect_status(): intResolve the redirect status for a fallback serve.
Return: int — Redirect status code.
publicstatic build_purge_fallback_headers()
public static function build_purge_fallback_headers(string $location, int $status): arrayBuild the headers for a fallback redirect (pure, testable). Parameter Type Default Description $locationstring— Absolute fallback URL. $statusint— Redirect status code.
Return: array{location: — string, status: int, headers: string[]} Headers to send.
public serve_purge_fallback_response()
public function serve_purge_fallback_response(array $response): boolServe a resolved purge fallback with a redirect. Parameter Type Default Description $responsearray— —
Return: bool — True when the fallback was served (or would be, under the test seam).
public maybe_serve_purge_fallback()
public function maybe_serve_purge_fallback(): voidServe the last-good fallback for Nginx `?wppo_purge_fallback=` misses.
Return: void.
public log_purge_fallback()
public function log_purge_fallback(): voidLog a purge-fallback serve (global once-per-day throttle).
Return: void.
public delete_used_css_file()
public function delete_used_css_file(string $file_path): boolDelete used-CSS file for a specific file path. Parameter Type Default Description $file_pathstring— The used-css file path.
Return: bool — True if successful (or not exists), false otherwise.
public delete_no_cache_marker()
public function delete_no_cache_marker(string $html_file_path): voidDelete the DONOTCACHEPAGE marker that lives beside a cached HTML file. Parameter Type Default Description $html_file_pathstring— The HTML cache file path whose directory holds the marker.
Return: void.
public delete_cache_files()
public function delete_cache_files($file_path): boolDelete cache files for a specific file path. Parameter Type Default Description $file_pathstring— The file path.
Return: bool — True if successful (or not exists), false otherwise.
public delete_role_variant_files()
public function delete_role_variant_files(string $dir): voidDelete all index-{hash}.html role-variant cache files in a directory. Parameter Type Default Description $dirstring— Directory to scan.
Return: void.
public clear_cache()
public function clear_cache(=null $url_path): boolClear the cache for a specific page or all pages. Parameter Type Default Description $url_path=null— The URL path of the page for which to clear the cache. If null, all cache will be cleared.
Return: bool — True on success, false on failure.
publicstatic delete_swap_dir_files()
public static function delete_swap_dir_files(string $swap_dir): voidRecursively delete files under an allowlisted swap dir via PHP API. Parameter Type Default Description $swap_dirstring— Allowlisted directory.
Return: void.
publicstatic purge_litespeed_swap_fallback()
public static function purge_litespeed_swap_fallback($url_path): voidFallback purge for LiteSpeed/OLS when LSCWP not active (P0). Parameter Type Default Description $url_pathstring|null— URL path or null for all.
Return: void.
public is_min_dir_allowed()
public function is_min_dir_allowed(string $dir): boolWhether a minify-cache directory may be recursively deleted. Parameter Type Default Description $dirstring— Absolute directory candidate.
Return: bool — True when the recursive delete may proceed.
public is_min_path()
public function is_min_path(string $path): boolWhether a file path lives under the min tree (for the PHP resolver). Parameter Type Default Description $pathstring— Absolute file candidate.
Return: bool — True when the path is min-tree-contained.
publicstatic purge_fallback_limits()
public static function purge_fallback_limits(): arrayResolve bounded purge-fallback snapshot limits.
Return: array{max_files: — int, max_depth: int, max_bytes: int, max_dirs: int, max_total_bytes: int} Limits.
public log_snapshot_cap()
public function log_snapshot_cap(): voidThrottled log when the snapshot bounds are hit.
Return: void.
public snapshot_domain_purge_fallbacks()
public function snapshot_domain_purge_fallbacks(string $dir): arraySnapshot domain-tree fallbacks under a directory slated for wipe. Parameter Type Default Description $dirstring— Absolute domain directory about to be deleted.
Return: array<string, — string> Fallback path => file contents.
public snapshot_min_purge_fallbacks()
public function snapshot_min_purge_fallbacks(string $dir): arraySnapshot min-tree fallbacks under a directory slated for wipe. Parameter Type Default Description $dirstring— Absolute min directory about to be deleted.
Return: array<string, — string> Fallback path => file contents.
public snapshot_purge_fallbacks_worker()
public function snapshot_purge_fallbacks_worker(string $dir, callable $is_allowed): arrayShared snapshot worker behind the domain/min entry points. Parameter Type Default Description $dirstring— Absolute directory about to be deleted. $is_allowedcallable— Containment validator: fn( string $path ): bool.
Return: array<string, — string> Fallback path => file contents.
public snapshot_purge_fallbacks()
public function snapshot_purge_fallbacks(string $dir, bool=false $min_tree): arraySnapshot last-good fallback files under a directory slated for wipe. Parameter Type Default Description $dirstring— Absolute directory about to be deleted. $min_treebool=false— Whether $dir lives under the min tree.
Return: array<string, — string> Fallback path => file contents.
public retain_live_bases_for_wipe()
public function retain_live_bases_for_wipe(string $dir, callable $is_allowed): voidRetain live bases to sibling fallbacks before a full-tree wipe. Parameter Type Default Description $dirstring— Absolute directory about to be deleted. $is_allowedcallable— Containment validator: fn( string $path ): bool.
Return: void.
public restore_purge_fallbacks()
public function restore_purge_fallbacks(array $snapshot): voidRestore domain-tree fallbacks after a full-cache wipe. Parameter Type Default Description $snapshotarray— —
Return: void.
public restore_min_fallbacks()
public function restore_min_fallbacks(array $snapshot): voidRestore min-tree fallbacks after a full-cache wipe. Parameter Type Default Description $snapshotarray— —
Return: void.
public restore_snapshot()
public function restore_snapshot(array $snapshot, callable $is_allowed): voidShared restore worker behind the domain/min entry points. Parameter Type Default Description $snapshotarray— — $is_allowedcallable— Containment validator: fn( string $path ): bool.
Return: void.
public stage_snapshot_to_temp()
public function stage_snapshot_to_temp(array $snapshot): arrayStage a snapshot to a temp dir outside the wipe tree. Parameter Type Default Description $snapshotarray— —
Return: array<string, — string> Original path => staged temp path.
public restore_staged_snapshot()
public function restore_staged_snapshot(array $staged, callable $is_allowed): voidRestore staged temp files back to their original paths. Parameter Type Default Description $stagedarray— — $is_allowedcallable— Containment validator: fn( string $path ): bool.
Return: void.
public delete_all_cache_files()
public function delete_all_cache_files(): boolDelete all cache files.
Return: bool — True if successful, false otherwise.
Hooks
Hooks referenced in includes/Cache/class-cache-invalidator.php: Hook Type Line Notes wppo_invalidation_urlsfilter 195 @param ×2 wppo_woo_invalidation_urlsfilter 542 @param ×3 wppo_purge_fallback_redirect_statusfilter 828 @param ×1 wppo_before_cache_clearaction 1159 @param ×1 wppo_after_cache_clearaction 1202 — wppo_litespeed_swap_purgefilter 1322 @param ×2 wppo_purge_fallback_limitsfilter 1509 @param ×1