pub struct LruQueryCache<T> { /* private fields */ }Expand description
Generic LRU cache keyed by CacheFingerprint.
Eviction policy: on evict_oldest, the entry with the oldest
last_accessed timestamp is removed. The insertion_order deque
maintains insertion ordering for O(1) oldest-insertion eviction fallback.
Hit/miss statistics are tracked across the lifetime of the cache.
Implementations§
Source§impl<T: Clone> LruQueryCache<T>
impl<T: Clone> LruQueryCache<T>
Sourcepub fn new(max_size: usize) -> Self
pub fn new(max_size: usize) -> Self
Create a new cache with the given maximum number of entries.
Sourcepub fn get(&mut self, key: &CacheFingerprint) -> Option<&T>
pub fn get(&mut self, key: &CacheFingerprint) -> Option<&T>
Look up a value by fingerprint.
Records a hit or miss and updates the entry’s access time on hit.
Sourcepub fn insert(&mut self, key: CacheFingerprint, value: T)
pub fn insert(&mut self, key: CacheFingerprint, value: T)
Insert a value into the cache.
If the cache is full and the key is not already present, evict_oldest
is called before insertion.
Sourcepub fn evict_oldest(&mut self)
pub fn evict_oldest(&mut self)
Evict the least-recently-used entry (the one with the oldest
last_accessed timestamp).
Falls back to evicting the oldest-inserted entry if all timestamps are equal (e.g., in tests).
Sourcepub fn hit_rate(&self) -> f64
pub fn hit_rate(&self) -> f64
Fraction of lookups that were cache hits: hits / (hits + misses).
Returns 0.0 if no lookups have occurred.
Sourcepub fn total_hits(&self) -> u64
pub fn total_hits(&self) -> u64
Total number of cache hits.
Sourcepub fn total_misses(&self) -> u64
pub fn total_misses(&self) -> u64
Total number of cache misses.
Auto Trait Implementations§
impl<T> Freeze for LruQueryCache<T>
impl<T> RefUnwindSafe for LruQueryCache<T>where
T: RefUnwindSafe,
impl<T> Send for LruQueryCache<T>where
T: Send,
impl<T> Sync for LruQueryCache<T>where
T: Sync,
impl<T> Unpin for LruQueryCache<T>where
T: Unpin,
impl<T> UnsafeUnpin for LruQueryCache<T>
impl<T> UnwindSafe for LruQueryCache<T>where
T: UnwindSafe,
Blanket Implementations§
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
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
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt 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.