Expand description
Thread-safe LRU cache with TTL-based expiry for GraphRAG query results.
§Design
This cache implements the Least Recently Used (LRU) eviction policy combined with Time-To-Live (TTL) expiry. Each cache entry carries a timestamp and TTL value; entries that have exceeded their TTL are treated as stale and evicted lazily on the next access.
§Thread Safety
The cache is wrapped in Arc<Mutex<...>> and exposes only &self methods
so it can be shared across threads and async tasks without additional
synchronization from the caller.
§Complexity
| Operation | Amortized | Worst-Case |
|---|---|---|
get | O(1) | O(1) |
put | O(1) | O(1) |
remove | O(1) | O(1) |
evict_expired | O(n) | O(n) |
The underlying doubly-linked-list + hash-map structure comes from the
lru crate.
Structs§
- Cache
Entry - A single cached value together with its metadata.
- Cache
Stats - Snapshot of cache performance metrics.
- Query
Cache - A thread-safe LRU cache with per-entry TTL expiry.
- Query
Cache Config - Configuration for
QueryCache.