pub struct SemanticQueryCache { /* private fields */ }Expand description
An in-memory cache for semantic search results with:
- FNV-1a fingerprinting — O(d) key computation over the query embedding.
- TTL expiry — stale entries are rejected on lookup and purged by
Self::evict_expired. - LRU eviction — when the cache is full the least-recently-used entry
(front of
access_order) is discarded. - Hit/miss statistics — exposed through
Self::stats.
Implementations§
Source§impl SemanticQueryCache
impl SemanticQueryCache
Sourcepub fn new(config: QueryCacheConfig) -> Self
pub fn new(config: QueryCacheConfig) -> Self
Create a new, empty cache with the given QueryCacheConfig.
Sourcepub fn get(&mut self, embedding: &[f32], current_tick: u64) -> Option<Vec<u64>>
pub fn get(&mut self, embedding: &[f32], current_tick: u64) -> Option<Vec<u64>>
Look up cached results for embedding at the given current_tick.
§Return value
Some(doc_ids)— cache hit;doc_idsis a clone of the stored result vector.None— cache miss (unknown key or expired entry).
Sourcepub fn put(
&mut self,
embedding: &[f32],
result_doc_ids: Vec<u64>,
current_tick: u64,
ttl_override: Option<u64>,
)
pub fn put( &mut self, embedding: &[f32], result_doc_ids: Vec<u64>, current_tick: u64, ttl_override: Option<u64>, )
Store result_doc_ids for embedding in the cache.
If an entry already exists for this embedding it is refreshed in-place (TTL reset, results replaced, hit_count zeroed). Otherwise a new entry is created, potentially evicting the LRU entry when the cache is full.
Pass ttl_override to use a TTL other than
QueryCacheConfig::default_ttl_ticks for this specific entry.
Sourcepub fn invalidate(&mut self, embedding: &[f32]) -> bool
pub fn invalidate(&mut self, embedding: &[f32]) -> bool
Remove the cache entry for embedding.
Returns true if an entry existed and was removed, false otherwise.
Sourcepub fn evict_expired(&mut self, current_tick: u64) -> usize
pub fn evict_expired(&mut self, current_tick: u64) -> usize
Remove all entries whose TTL has elapsed at current_tick.
Returns the number of entries removed. Each removed entry increments
QueryCacheStats::expirations.
Sourcepub fn stats(&self) -> &QueryCacheStats
pub fn stats(&self) -> &QueryCacheStats
Return a shared reference to the accumulated cache statistics.
Auto Trait Implementations§
impl Freeze for SemanticQueryCache
impl RefUnwindSafe for SemanticQueryCache
impl Send for SemanticQueryCache
impl Sync for SemanticQueryCache
impl Unpin for SemanticQueryCache
impl UnsafeUnpin for SemanticQueryCache
impl UnwindSafe for SemanticQueryCache
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.