pub struct EvaluationCache<T: Float + Debug + Send + Sync + 'static> { /* private fields */ }Expand description
Evaluation cache for storing results
Entries are evicted according to CacheEvictionPolicy once the cache
exceeds its capacity. The default policy is LRU: the entry whose last access
is oldest is dropped first.
Implementations§
Source§impl<T: Float + Debug + Default + Send + Sync> EvaluationCache<T>
impl<T: Float + Debug + Default + Send + Sync> EvaluationCache<T>
Sourcepub fn with_capacity(
capacity: usize,
eviction_policy: CacheEvictionPolicy,
) -> Self
pub fn with_capacity( capacity: usize, eviction_policy: CacheEvictionPolicy, ) -> Self
Create a cache with an explicit capacity and eviction policy.
A capacity of zero is promoted to one so the cache always retains the most recent insertion.
Sourcepub fn stats(&self) -> &CacheMetadata
pub fn stats(&self) -> &CacheMetadata
Get cache statistics
Sourcepub fn total_accesses(&self) -> usize
pub fn total_accesses(&self) -> usize
Total number of cache reads recorded across all live entries.
Sourcepub fn access_frequency(&self, key: &str) -> Option<usize>
pub fn access_frequency(&self, key: &str) -> Option<usize>
Number of times key has been read out of the cache, or None if it is
not resident.
The access frequency used to be tracked a second time, in an
AccessPatterns.frequency_distribution map that nothing ever read; the
per-entry counter that already drives LFU eviction is the single source of
truth now. AccessPatterns also carried temporal_patterns and
correlation_patterns — a Vec and a HashMap that were constructed
empty, never written and never read, describing an access-pattern analysis
this cache does not perform. Both are gone.
Sourcepub fn hottest_key(&self) -> Option<&str>
pub fn hottest_key(&self) -> Option<&str>
Key of the most-read resident entry, ties broken by key so the answer is
deterministic. None when the cache is empty.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for EvaluationCache<T>
impl<T> RefUnwindSafe for EvaluationCache<T>
impl<T> Send for EvaluationCache<T>
impl<T> Sync for EvaluationCache<T>
impl<T> Unpin for EvaluationCache<T>
impl<T> UnsafeUnpin for EvaluationCache<T>
impl<T> UnwindSafe for EvaluationCache<T>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 more