class-cache-invalidator.php

Cache invalidation/purge service — invalidation policy, deletion mechanics, purge-fallback serving, and LiteSpeed swap purge.

Source includes/Cache/class-cache-invalidator.php8 min readPart of Performance Optimisation

includes/Cache/class-cache-invalidator.php

Cache invalidation/purge service — invalidation policy, deletion mechanics, purge-fallback serving, and LiteSpeed swap purge.

Namespace: PerformanceOptimise\\Inc · Lines: 2204

Class Cache_Invalidator

Class Cache_Invalidator

Source: includes/Cache/class-cache-invalidator.php, line 76

final class Cache_Invalidator

Tags: @since 2.4.0

Constants

ConstantVisibilityValueLine
PURGE_FALLBACK_MAX_FILESpublic25113
PURGE_FALLBACK_MAX_DEPTHpublic6114
PURGE_FALLBACK_MAX_BYTESpublic512 * 1024115
PURGE_FALLBACK_MAX_DIRSpublic200116
PURGE_FALLBACK_MAX_TOTAL_BYTESpublic2 * 1024 * 1024118
PURGE_FALLBACK_REDIRECT_STATUSpublic302120
PURGE_FALLBACK_NAMESpublicarray( \'fallback.css\', \'fallback.js\', \'fallback.mobile.css\', \'fallback.desktop.css\', \'fallback.mobile.js\', \'fallback.desktop.js\' )123

Properties

PropertyVisibilityTypeDefaultLine
$cacheprivateCache—88

public __construct()

public function __construct(Cache $cache)

Constructor.

ParameterTypeDefaultDescription
$cacheCache—Cache instance (state + storage/policy owner).

Tags: @since 2.4.0

Source: includes/Cache/class-cache-invalidator.php, line 96

public invalidate_dynamic_static_html()

public function invalidate_dynamic_static_html($page_id): void

Invalidate dynamic static HTML cache for a specific page and global archives.

ParameterTypeDefaultDescription
$page_idint—The page ID.

Return: void.

Tags: @since 1.0.0

Source: includes/Cache/class-cache-invalidator.php, line 133

public invalidate_single_static_html()

public function invalidate_single_static_html(int $page_id, bool=true $bump_stats): void

Invalidate the static HTML cache for a single post URL only.

ParameterTypeDefaultDescription
$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.

Tags: @since 2.0.0

Source: includes/Cache/class-cache-invalidator.php, line 372

public invalidate_woo_object()

public function invalidate_woo_object(int $object_id, string $kind): void

Surgically invalidate cache for a WooCommerce product, order, or coupon.

ParameterTypeDefaultDescription
$object_idint—Woo object (product/order/coupon) ID.
$kindstring—Object kind: \’product\’, \’order\’, or \’coupon\’.

Return: void.

Tags: @since 2.0.0

Source: includes/Cache/class-cache-invalidator.php, line 463

publicstatic get_purge_fallback_path()

public static function get_purge_fallback_path(string $file_path): string

Map a derived asset path to its sibling last-good fallback path.

ParameterTypeDefaultDescription
$file_pathstring—Absolute derived-asset path.

Return: string — Sibling fallback path, or \’\’ when not applicable.

Tags: @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 646

public retain_purge_fallback()

public function retain_purge_fallback(string $file_path): void

Retain a last-good fallback copy before a derived file is purged.

ParameterTypeDefaultDescription
$file_pathstring—The derived file about to be deleted.

Return: void.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 676

public get_purge_fallback_response()

public function get_purge_fallback_response(string $requested_path): array

Resolve a post-purge miss under the cache path to its fallback.

ParameterTypeDefaultDescription
$requested_pathstring—Absolute requested derived-asset path.

Return: array{served: — bool, status: int, fallback_path: string, location: string} Resolution.

Tags: @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 715

publicstatic purge_fallback_redirect_status()

public static function purge_fallback_redirect_status(): int

Resolve the redirect status for a fallback serve.

Return: int — Redirect status code.

Tags: @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 818

publicstatic build_purge_fallback_headers()

public static function build_purge_fallback_headers(string $location, int $status): array

Build the headers for a fallback redirect (pure, testable).

ParameterTypeDefaultDescription
$locationstring—Absolute fallback URL.
$statusint—Redirect status code.

Return: array{location: — string, status: int, headers: string[]} Headers to send.

Tags: @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 853

public serve_purge_fallback_response()

public function serve_purge_fallback_response(array $response): bool

Serve a resolved purge fallback with a redirect.

ParameterTypeDefaultDescription
$responsearray——

Return: bool — True when the fallback was served (or would be, under the test seam).

Tags: @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 882

public maybe_serve_purge_fallback()

public function maybe_serve_purge_fallback(): void

Serve the last-good fallback for Nginx `?wppo_purge_fallback=` misses.

Return: void.

Tags: @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 936

public log_purge_fallback()

public function log_purge_fallback(): void

Log a purge-fallback serve (global once-per-day throttle).

Return: void.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 996

public delete_used_css_file()

public function delete_used_css_file(string $file_path): bool

Delete used-CSS file for a specific file path.

ParameterTypeDefaultDescription
$file_pathstring—The used-css file path.

Return: bool — True if successful (or not exists), false otherwise.

Tags: @internal · @since 1.9.0

Source: includes/Cache/class-cache-invalidator.php, line 1023

public delete_no_cache_marker()

public function delete_no_cache_marker(string $html_file_path): void

Delete the DONOTCACHEPAGE marker that lives beside a cached HTML file.

ParameterTypeDefaultDescription
$html_file_pathstring—The HTML cache file path whose directory holds the marker.

Return: void.

Tags: @internal · @since 1.9.0

Source: includes/Cache/class-cache-invalidator.php, line 1039

public delete_cache_files()

public function delete_cache_files($file_path): bool

Delete cache files for a specific file path.

ParameterTypeDefaultDescription
$file_pathstring—The file path.

Return: bool — True if successful (or not exists), false otherwise.

Tags: @internal · @since 1.1.0

Source: includes/Cache/class-cache-invalidator.php, line 1064

public delete_role_variant_files()

public function delete_role_variant_files(string $dir): void

Delete all index-{hash}.html role-variant cache files in a directory.

ParameterTypeDefaultDescription
$dirstring—Directory to scan.

Return: void.

Tags: @internal · @since 1.9.0

Source: includes/Cache/class-cache-invalidator.php, line 1109

public clear_cache()

public function clear_cache(=null $url_path): bool

Clear the cache for a specific page or all pages.

ParameterTypeDefaultDescription
$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.

Tags: @since 1.1.1

Source: includes/Cache/class-cache-invalidator.php, line 1157

publicstatic delete_swap_dir_files()

public static function delete_swap_dir_files(string $swap_dir): void

Recursively delete files under an allowlisted swap dir via PHP API.

ParameterTypeDefaultDescription
$swap_dirstring—Allowlisted directory.

Return: void.

Tags: @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1273

publicstatic purge_litespeed_swap_fallback()

public static function purge_litespeed_swap_fallback($url_path): void

Fallback purge for LiteSpeed/OLS when LSCWP not active (P0).

ParameterTypeDefaultDescription
$url_pathstring|null—URL path or null for all.

Return: void.

Tags: @since 2.0.0

Source: includes/Cache/class-cache-invalidator.php, line 1308

public is_min_dir_allowed()

public function is_min_dir_allowed(string $dir): bool

Whether a minify-cache directory may be recursively deleted.

ParameterTypeDefaultDescription
$dirstring—Absolute directory candidate.

Return: bool — True when the recursive delete may proceed.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1398

public is_min_path()

public function is_min_path(string $path): bool

Whether a file path lives under the min tree (for the PHP resolver).

ParameterTypeDefaultDescription
$pathstring—Absolute file candidate.

Return: bool — True when the path is min-tree-contained.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1445

publicstatic purge_fallback_limits()

public static function purge_fallback_limits(): array

Resolve bounded purge-fallback snapshot limits.

Return: array{max_files: — int, max_depth: int, max_bytes: int, max_dirs: int, max_total_bytes: int} Limits.

Tags: @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1473

public log_snapshot_cap()

public function log_snapshot_cap(): void

Throttled log when the snapshot bounds are hit.

Return: void.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1545

public snapshot_domain_purge_fallbacks()

public function snapshot_domain_purge_fallbacks(string $dir): array

Snapshot domain-tree fallbacks under a directory slated for wipe.

ParameterTypeDefaultDescription
$dirstring—Absolute domain directory about to be deleted.

Return: array<string, — string> Fallback path => file contents.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1579

public snapshot_min_purge_fallbacks()

public function snapshot_min_purge_fallbacks(string $dir): array

Snapshot min-tree fallbacks under a directory slated for wipe.

ParameterTypeDefaultDescription
$dirstring—Absolute min directory about to be deleted.

Return: array<string, — string> Fallback path => file contents.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1602

public snapshot_purge_fallbacks_worker()

public function snapshot_purge_fallbacks_worker(string $dir, callable $is_allowed): array

Shared snapshot worker behind the domain/min entry points.

ParameterTypeDefaultDescription
$dirstring—Absolute directory about to be deleted.
$is_allowedcallable—Containment validator: fn( string $path ): bool.

Return: array<string, — string> Fallback path => file contents.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1624

public snapshot_purge_fallbacks()

public function snapshot_purge_fallbacks(string $dir, bool=false $min_tree): array

Snapshot last-good fallback files under a directory slated for wipe.

ParameterTypeDefaultDescription
$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.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1748

public retain_live_bases_for_wipe()

public function retain_live_bases_for_wipe(string $dir, callable $is_allowed): void

Retain live bases to sibling fallbacks before a full-tree wipe.

ParameterTypeDefaultDescription
$dirstring—Absolute directory about to be deleted.
$is_allowedcallable—Containment validator: fn( string $path ): bool.

Return: void.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1776

public restore_purge_fallbacks()

public function restore_purge_fallbacks(array $snapshot): void

Restore domain-tree fallbacks after a full-cache wipe.

ParameterTypeDefaultDescription
$snapshotarray——

Return: void.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1846

public restore_min_fallbacks()

public function restore_min_fallbacks(array $snapshot): void

Restore min-tree fallbacks after a full-cache wipe.

ParameterTypeDefaultDescription
$snapshotarray——

Return: void.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1867

public restore_snapshot()

public function restore_snapshot(array $snapshot, callable $is_allowed): void

Shared restore worker behind the domain/min entry points.

ParameterTypeDefaultDescription
$snapshotarray——
$is_allowedcallable—Containment validator: fn( string $path ): bool.

Return: void.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1894

public stage_snapshot_to_temp()

public function stage_snapshot_to_temp(array $snapshot): array

Stage a snapshot to a temp dir outside the wipe tree.

ParameterTypeDefaultDescription
$snapshotarray——

Return: array<string, — string> Original path => staged temp path.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 1964

public restore_staged_snapshot()

public function restore_staged_snapshot(array $staged, callable $is_allowed): void

Restore staged temp files back to their original paths.

ParameterTypeDefaultDescription
$stagedarray——
$is_allowedcallable—Containment validator: fn( string $path ): bool.

Return: void.

Tags: @internal · @since 2.2.0

Source: includes/Cache/class-cache-invalidator.php, line 2031

public delete_all_cache_files()

public function delete_all_cache_files(): bool

Delete all cache files.

Return: bool — True if successful, false otherwise.

Tags: @internal · @since 1.0.0

Source: includes/Cache/class-cache-invalidator.php, line 2084

Hooks

Hooks referenced in includes/Cache/class-cache-invalidator.php:

HookTypeLineNotes
wppo_invalidation_urlsfilter195@param ×2
wppo_woo_invalidation_urlsfilter542@param ×3
wppo_purge_fallback_redirect_statusfilter828@param ×1
wppo_before_cache_clearaction1159@param ×1
wppo_after_cache_clearaction1202—
wppo_litespeed_swap_purgefilter1322@param ×2
wppo_purge_fallback_limitsfilter1509@param ×1