Skip to main content

Module query_cache

Module query_cache 

Source
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

OperationAmortizedWorst-Case
getO(1)O(1)
putO(1)O(1)
removeO(1)O(1)
evict_expiredO(n)O(n)

The underlying doubly-linked-list + hash-map structure comes from the lru crate.

Structs§

CacheEntry
A single cached value together with its metadata.
CacheStats
Snapshot of cache performance metrics.
QueryCache
A thread-safe LRU cache with per-entry TTL expiry.
QueryCacheConfig
Configuration for QueryCache.