Implement a caching layer that reduces redundant LLM calls while maintaining response relevance for dynamic queries.
Implement get_cached_response using normalized-token similarity, a relevance threshold, TTL expiration, and LRU eviction. On a cache miss, obtain the response from the supplied llm_responses mapping, store it, and return the updated cache.
The function receives a cache list and returns an object containing the response, whether the result was cached, and the updated cache. Cache entries use query, response, created_at, and last_used fields.
def get_cached_response(query, now, cache, ttl, similarity_threshold, capacity, llm_responses):