buildCacheKey($prompt); $item = $this->cache->getItem($key); if ($item->isHit()) { $cached = $item->get(); return is_array($cached) ? $cached : []; } $result = $this->inner->retrieve($prompt); $item->set($result); $item->expiresAfter($this->ttlSeconds); $this->cache->save($item); return $result; } private function buildCacheKey(string $prompt): string { $normalized = mb_strtolower(trim($prompt)); $normalized = preg_replace('/\s+/u', ' ', $normalized) ?? $normalized; return 'rag_retrieval_' . sha1($normalized); } }