Skip to content

SlotCache

Reading and writing a slot’s rendered content to the shared cache.

Two things here are not a plain get/set.

The key has to change whenever anything the render depended on changes, so it folds in the module, action, output type, a digest of the slot’s arguments, and — when the action declares cache tags — the current version of each tag’s namespace. Bumping a tag’s version therefore invalidates every slot carrying it without touching the cache itself.

The payload carries its own monotonic expiry stamp, checked independently of the backend’s wall-clock expiry, so a cache whose clock disagrees with this process cannot serve content the slot already considers stale.

A cache that cannot be read or written is a miss, never an error: the page is still correct, only slower, and that is not worth failing a request over. It is reported, because a cache silently doing nothing is a performance cliff nobody notices.

final readonly class SlotCache

SourceExecution/Slot/SlotCache.php

public function __construct(CategoryLogger $logger, string $slotKey, RandomnessInterface $randomness = new SystemRandomness(…)): mixed

ParameterTypeDescription
$loggerCategoryLogger
$slotKeystring
$randomnessRandomnessInterface

Returns mixed

MethodDescription
decode(mixed $cached): ?stringUnwraps a stored payload, or null when it is a miss or has expired.
encode(string $content, ?int $ttl): stringWraps content with its expiry stamp when an explicit TTL is given.
keyFor(string $module, string $action, string $outputType, array<string, mixed> $parameters, array<int, mixed> $tags): stringComposes the cache key for one slot render.
read(string $cacheKey): ?stringThe cached content, or null on a miss, an expired stamp, or an unreadable cache.
write(string $cacheKey, string $content, ?int $ttl): voidStores the rendered content.

public function decode(mixed $cached): ?string

Unwraps a stored payload, or null when it is a miss or has expired.

An unwrapped string is always a hit: it was stored without a TTL, so its freshness is the backend’s business.

ParameterTypeDescription
$cachedmixed

Returns ?``string

public function encode(string $content, ?int $ttl): string

Wraps content with its expiry stamp when an explicit TTL is given.

Without one the backend’s own default expiry governs and the content is stored raw. Content that will not survive json_encode is also stored raw rather than dropped: losing the entry is worse than losing its stamp.

ParameterTypeDescription
$contentstring
$ttl?``int

Returns string

public function keyFor(string $module, string $action, string $outputType, array<string, mixed> $parameters, array<int, mixed> $tags): string

Composes the cache key for one slot render.

ParameterTypeDescription
$modulestring
$actionstring
$outputTypestring
$parametersarray``<``string``, ``mixed``>
$tagsarray``<``int``, ``mixed``>

Returns string

public function read(string $cacheKey): ?string

The cached content, or null on a miss, an expired stamp, or an unreadable cache.

ParameterTypeDescription
$cacheKeystring

Returns ?``string

public function write(string $cacheKey, string $content, ?int $ttl): void

Stores the rendered content.

A failure leaves the page correct and only slower.

ParameterTypeDescription
$cacheKeystring
$contentstring
$ttl?``int