store = $store; } /** * Read the cached search-result payload, or null on miss / * expired. * * @param string $key Cache key. * * @return array|null */ public function get( string $key ): ?array { $entry = $this->store->getRaw( $key ); if ( null === $entry ) { return null; } $value = $entry->value(); if ( ! is_array( $value ) ) { // Defensive: a non-array 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 SearchCache::get() contract. return null; } /** @var array $value */ return $value; } /** * Write the search-result payload with the given TTL in * seconds. Delegates TTL validation to {@see InMemoryCacheStore::putRaw()}. * * @param string $key Cache key. * @param array $payload Normalized search result. * @param int $ttlSeconds TTL in seconds; must be > 0. */ public function put( string $key, array $payload, int $ttlSeconds ): void { $this->store->putRaw( $key, $payload, $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(); } }