class-cache-capacity.php

Cache capacity/accounting owner.

Source includes/Cache/class-cache-capacity.php5 min readPart of Performance Optimisation

includes/Cache/class-cache-capacity.php

Cache capacity/accounting owner.

Namespace: PerformanceOptimise\\Inc · Lines: 914

Class Cache_Capacity

Cache statistics, capacity, and eviction service.

Source: includes/Cache/class-cache-capacity.php, line 27

final class Cache_Capacity

Tags: @since NEXT

Properties

PropertyVisibilityTypeDefaultLine
$cacheprivateCache—35
$depth_warning_loggedprivate staticboolfalse43

public __construct()

public function __construct(Cache $cache)

Constructor.

ParameterTypeDefaultDescription
$cacheCache—Cache owner providing narrow state/deletion bridges.

Tags: @since NEXT

Source: includes/Cache/class-cache-capacity.php, line 51

public get_cache_size()

public function get_cache_size(): string

Get the size of the cache.

Return: string.

Tags: @since 1.0.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 63

public get_cache_stats()

public function get_cache_stats(): array

Get detailed cache statistics.

Return: array{size: — string, cached_pages: int, last_cleared: string, cache_dir: string}.

Tags: @since 2.0.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 94

public store_cache_stats()

public function store_cache_stats(array $unified, string $stats_key): void

Store the unified cache-stats payload in the salted object cache (WP 6.9+) and the transient fallback.

ParameterTypeDefaultDescription
$unifiedarray—Unified stats payload.
$stats_keystring—Transient key (multisite-prefixed).

Return: void.

Tags: @since 2.0.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 245

public list_cache_children()

public function list_cache_children(string $directory): ?array

List direct children of a cache directory via the WP filesystem.

ParameterTypeDefaultDescription
$directorystring—Directory path.

Return: array|null — Dirlist entries, or null when unavailable.

Tags: @since 2.2.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 265

public calculate_directory_stats()

public function calculate_directory_stats(string $directory, int=0 $depth): array

Calculate directory size and cached-page count in a single walk.

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

Tags: @since 2.0.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 292

public calculate_directory_size()

public function calculate_directory_size(string $directory, int=0 $depth): int

Calculate the size of a directory.

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

Tags: @since 1.0.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 358

public count_cached_pages()

public function count_cached_pages(string $directory, int=0 $depth): int

Recursively count cached pages by counting index.html files in the cache directory.

ParameterTypeDefaultDescription
$directorystring—The directory to scan.
$depthint=0—Recursion depth guard.

Return: int — Number of index.html files found.

Tags: @since 1.9.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 373

publicstatic get_cache_cap_settings()

public static function get_cache_cap_settings(): array

Read 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}.

Tags: @since 2.2.0 · @since 2.3.0 Disk-safe slice (issue #1428): `max_files`/`randomized_guard` keys. · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 394

public get_cache_bytes_and_files()

public function get_cache_bytes_and_files(): array

Total static-cache bytes + file count in a single directory walk.

Return: array{bytes:int,files:int} — Bytes used and file count.

Tags: @since 2.3.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 455

public get_cache_size_bytes()

public function get_cache_size_bytes(): int

Total static-cache size in bytes for the current domain.

Return: int — Bytes used, or 0 on failure.

Tags: @since 2.2.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 498

public get_cache_file_count()

public function get_cache_file_count(): int

Total cached-page file count for the current domain.

Return: int — File count, or 0 on failure.

Tags: @since 2.3.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 515

publicstatic is_randomized_query_asset()

public static function is_randomized_query_asset(string $src): bool

Whether an asset URL carries a randomized per-request query value.

ParameterTypeDefaultDescription
$srcstring—Asset src URL.

Return: bool — True when the query looks randomized.

Tags: @since 2.3.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 535

public get_cache_cap_status()

public function get_cache_cap_status(): array

Warn-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}.

Tags: @since 2.2.0 · @since 2.3.0 File-count dimension (issue #1428): `files`/`cap_files`/`warn_files` fields. · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 608

public maybe_enforce_cache_cap()

public function maybe_enforce_cache_cap(): void

Warn-before-enforce size+count cap check after a cache write.

Return: void.

Tags: @since 2.2.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 685

public evict_oldest_cache_entries()

public function evict_oldest_cache_entries(int $bytes_to_free): int

Evict oldest cached pages until at least the given bytes are freed.

ParameterTypeDefaultDescription
$bytes_to_freeint—Minimum bytes to reclaim.

Return: int — Bytes actually freed (best effort).

Tags: @since 2.2.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 760

public evict_oldest_cache_files_by_count()

public function evict_oldest_cache_files_by_count(int $files_to_free): int

Evict oldest cached pages until the file count drops by the given amount.

ParameterTypeDefaultDescription
$files_to_freeint—Minimum entries to remove.

Return: int — Entries actually removed (best effort).

Tags: @since 2.3.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 811

public collect_cache_entries_by_age()

public function collect_cache_entries_by_age(string $directory, int=0 $depth, array&=array() $out): array

Collect cache `index.html` entries with mtime + size for eviction.

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

Tags: @since 2.2.0 · @since NEXT Extracted with the Cache_Capacity accounting owner.

Source: includes/Cache/class-cache-capacity.php, line 863