Skip to content

CassetteKeyScheme

Derives an object-store key from a cassette id and the hour it was recorded in:

{prefix}/{env}/{yyyy}/{mm}/{dd}/{hh}/{id}.qcast

Time-partitioned so a lifecycle rule and a “what happened this hour” prefix listing are both trivial, and so a flat container holding a year of cassettes never has to be enumerated whole. Always partitions by the cassette’s own recorded hour, forced to UTC — never the current time and never the server’s local timezone — so a cassette fetched a day later resolves to the same key regardless of which timezone the fetching process happens to run in, and two servers in different timezones never partition the same instant into different hour buckets.

Uses CassetteId::$slug, never $id->raw, for the final path segment: an adopted correlation id can carry /, . or .. straight through Quiote\Support\CorrelationId::sanitize() (verified against that class, not assumed), and $slug is what already reduces that to a safe, bounded identifier — see CassetteId’s own docblock.

final readonly class CassetteKeyScheme

SourceCassetteKeyScheme.php

public function __construct(string $prefix, string $env): mixed

ParameterTypeDescription
$prefixstring
$envstring

Returns mixed

MethodDescription
dayPrefix(DateTimeImmutable $dt): stringThe key prefix for every cassette recorded during $dt’s UTC calendar day — one level up from CassetteKeyScheme::hourPrefix(), for a delimited listObjects() call that enumerates that day’s hour buckets as common prefixes rather than every object in it.
hourPrefix(DateTimeImmutable $dt): stringThe key prefix for every cassette recorded during $dt’s hour, for a bounded backward probe or a listing.
keyFor(CassetteId $id, ?DateTimeImmutable $recordedAt, DateTimeImmutable $fallback): stringThe key a cassette recorded at $recordedAt (or, absent that, $fallback) is written under.

public function dayPrefix(DateTimeImmutable $dt): string

The key prefix for every cassette recorded during $dt’s UTC calendar day — one level up from CassetteKeyScheme::hourPrefix(), for a delimited listObjects() call that enumerates that day’s hour buckets as common prefixes rather than every object in it.

ParameterTypeDescription
$dtDateTimeImmutable

Returns string

public function hourPrefix(DateTimeImmutable $dt): string

The key prefix for every cassette recorded during $dt’s hour, for a bounded backward probe or a listing.

ParameterTypeDescription
$dtDateTimeImmutable

Returns string

public function keyFor(CassetteId $id, ?DateTimeImmutable $recordedAt, DateTimeImmutable $fallback): string

The key a cassette recorded at $recordedAt (or, absent that, $fallback) is written under.

ParameterTypeDescription
$idCassetteId
$recordedAt?DateTimeImmutable
$fallbackDateTimeImmutable

Returns string