Skip to main content

Module query_cache

Module query_cache 

Source
Expand description

Server-side query result cache

Provides an LRU cache with TTL-based expiry for caching serialized query results. Repeated identical queries (especially expensive FHE filter queries) are served from cache, dramatically reducing latency. The cache supports collection-level invalidation so that write operations (PUT/DELETE/UPDATE) automatically clear stale entries for the affected collection.

§Architecture

  • CacheKey: blake3 hash of the serialized query (query type + parameters).
  • CacheEntry: stores the serialized result bytes, creation time, TTL, access count, and byte size.
  • QueryCache: thread-safe LRU cache protected by parking_lot::RwLock. Supports concurrent reads; writes acquire an exclusive lock.
  • CacheStats: atomic counters for hits, misses, evictions, and insertions.

§Write-through invalidation

On mutating operations the caller should invoke QueryCache::invalidate with the affected collection name. This removes every cached entry that was stored under that collection, ensuring stale data is never served.

Structs§

CacheKey
Opaque cache key derived from a blake3 hash of the serialized query.
CacheStats
Accumulated cache statistics.
CacheStatsSnapshot
A point-in-time snapshot of cache statistics.
QueryCache
Thread-safe LRU cache for server-side query results.