includes/Cache/class-cache-capacity.php
Cache capacity/accounting owner.
Class Cache_Capacity
Cache statistics, capacity, and eviction service.
final class Cache_CapacityProperties
| Property | Visibility | Type | Default | Line |
|---|---|---|---|---|
$cache | private | Cache | — | 35 |
$depth_warning_logged | private static | bool | false | 43 |
public __construct()
public function __construct(Cache $cache)Constructor. Parameter Type Default Description $cacheCache— Cache owner providing narrow state/deletion bridges.
public get_cache_size()
public function get_cache_size(): stringGet the size of the cache.
Return: string.
public get_cache_stats()
public function get_cache_stats(): arrayGet detailed cache statistics.
Return: array{size: — string, cached_pages: int, last_cleared: string, cache_dir: string}.
public store_cache_stats()
public function store_cache_stats(array $unified, string $stats_key): voidStore the unified cache-stats payload in the salted object cache (WP 6.9+) and the transient fallback. Parameter Type Default Description $unifiedarray— Unified stats payload. $stats_keystring— Transient key (multisite-prefixed).
Return: void.
public list_cache_children()
public function list_cache_children(string $directory): ?arrayList direct children of a cache directory via the WP filesystem. Parameter Type Default Description $directorystring— Directory path.
Return: array|null — Dirlist entries, or null when unavailable.
public calculate_directory_stats()
public function calculate_directory_stats(string $directory, int=0 $depth): arrayCalculate directory size and cached-page count in a single walk. Parameter Type Default Description $directorystring— The path to the directory to scan. $depthint=0— Recursion depth guard.
Return: array{size:int,count:int} — Total bytes and index.html count.
public calculate_directory_size()
public function calculate_directory_size(string $directory, int=0 $depth): intCalculate the size of a directory. Parameter Type Default Description $directorystring— The path to the directory whose size is to be calculated. $depthint=0— Recursion depth guard.
Return: int — The total size of the directory in bytes.
public count_cached_pages()
public function count_cached_pages(string $directory, int=0 $depth): intRecursively count cached pages by counting index.html files in the cache directory. Parameter Type Default Description $directorystring— The directory to scan. $depthint=0— Recursion depth guard.
Return: int — Number of index.html files found.
publicstatic get_cache_cap_settings()
public static function get_cache_cap_settings(): arrayRead the bounded-cache cap settings with fail-safe defaults.
Return: array{max_mb:int,warn_ratio:float,enforce:bool,max_files:int,randomized_guard:bool}.
public get_cache_bytes_and_files()
public function get_cache_bytes_and_files(): arrayTotal static-cache bytes + file count in a single directory walk.
Return: array{bytes:int,files:int} — Bytes used and file count.
public get_cache_size_bytes()
public function get_cache_size_bytes(): intTotal static-cache size in bytes for the current domain.
Return: int — Bytes used, or 0 on failure.
public get_cache_file_count()
public function get_cache_file_count(): intTotal cached-page file count for the current domain.
Return: int — File count, or 0 on failure.
publicstatic is_randomized_query_asset()
public static function is_randomized_query_asset(string $src): boolWhether an asset URL carries a randomized per-request query value. Parameter Type Default Description $srcstring— Asset src URL.
Return: bool — True when the query looks randomized.
public get_cache_cap_status()
public function get_cache_cap_status(): arrayWarn-before-enforce cap status for the current domain cache.
Return: array{bytes:int,cap_bytes:int,warn_bytes:int,state:string,enforce:bool,max_mb:int,files:int,cap_files:int,warn_files:int}.
public maybe_enforce_cache_cap()
public function maybe_enforce_cache_cap(): voidWarn-before-enforce size+count cap check after a cache write.
Return: void.
public evict_oldest_cache_entries()
public function evict_oldest_cache_entries(int $bytes_to_free): intEvict oldest cached pages until at least the given bytes are freed. Parameter Type Default Description $bytes_to_freeint— Minimum bytes to reclaim.
Return: int — Bytes actually freed (best effort).
public evict_oldest_cache_files_by_count()
public function evict_oldest_cache_files_by_count(int $files_to_free): intEvict oldest cached pages until the file count drops by the given amount. Parameter Type Default Description $files_to_freeint— Minimum entries to remove.
Return: int — Entries actually removed (best effort).
public collect_cache_entries_by_age()
public function collect_cache_entries_by_age(string $directory, int=0 $depth, array&=array() $out): arrayCollect cache `index.html` entries with mtime + size for eviction. Parameter Type Default Description $directorystring— Directory to scan. $depthint=0— Recursion depth guard. $outarray&=array()— Accumulator (passed by reference).
Return: array<int, — array{path:string,mtime:int,size:int}> Collected entries.