store = $store; } /** * Read the cached {@see ProviderHealthStatus}, or null on * miss / expired. * * @param string $key Cache key. */ public function get( string $key ): ?ProviderHealthStatus { $entry = $this->store->getRaw( $key ); if ( null === $entry ) { return null; } $value = $entry->value(); if ( ! $value instanceof ProviderHealthStatus ) { // Defensive: a non-ProviderHealthStatus value would only // occur if the underlying store were misused by another // caller; treat it as a miss rather than surfacing a // typed payload that violates the // ProviderHealthCache::get() contract. return null; } return $value; } /** * Write the {@see ProviderHealthStatus} with the given TTL in * seconds. Delegates TTL validation to * {@see InMemoryCacheStore::putRaw()}. * * @param string $key Cache key. * @param ProviderHealthStatus $status Health snapshot to store. * @param int $ttlSeconds TTL in seconds; must be > 0. */ public function put( string $key, ProviderHealthStatus $status, int $ttlSeconds ): void { $this->store->putRaw( $key, $status, $ttlSeconds ); } /** * Remove the entry stored under `$key`. Idempotent. * * @param string $key Cache key. */ public function forget( string $key ): void { $this->store->forget( $key ); } /** * Drop every entry stored in this layer's backing store. */ public function flush(): void { $this->store->flush(); } }