Skip to main content

Module versioned_cache

Module versioned_cache 

Source
Expand description

Versioned Inference Cache with Atomic KB Invalidation

Extends the basic InferenceCache with explicit version tracking per knowledge base. When a knowledge base is updated, all cached inferences for that KB are atomically invalidated in O(n) time, where n is the number of cached entries for that KB.

§Design

  • CacheKey identifies an inference result by goal hash, KB identity, and KB version.
  • CacheEntry stores variable bindings, a TTL, and a hit counter.
  • VersionedInferenceCache is a concurrent, version-aware cache backed by RwLock<HashMap>.
  • CacheStats tracks inserts/hits/misses/invalidations/evictions via AtomicU64.

§Thread Safety

All public methods are &self (shared reference). Internal mutation is protected by RwLock. CacheStats uses AtomicU64 with Relaxed ordering for performance — exact ordering guarantees are not required for statistics counters.

Structs§

CacheEntry
A single cached inference result.
CacheKey
Composite key for a single cached inference result.
CacheStats
Atomic statistics counters for VersionedInferenceCache.
CacheStatsSnapshot
A point-in-time snapshot of CacheStats.
VersionedInferenceCache
Concurrent, version-aware memoization cache for inference results.

Enums§

CacheError
Errors that can occur when interacting with VersionedInferenceCache.