pub struct Cache<K, V> { /* private fields */ }Expand description
LRU-like cache using DashMap
Uses atomic counters for LRU approximation and metrics
Implementations§
Source§impl<K, V> Cache<K, V>
impl<K, V> Cache<K, V>
Sourcepub fn put(&self, key: K, value: V) -> Option<V>
pub fn put(&self, key: K, value: V) -> Option<V>
Put value in cache - lock-free with atomic eviction
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Check if key exists - lock-free
Sourcepub fn get_stats(&self) -> CacheStats
pub fn get_stats(&self) -> CacheStats
Get cache statistics - all atomic reads Gets comprehensive statistics about the cache
§Panics
Panics if the system time is before UNIX_EPOCH (should never happen in practice)
Sourcepub fn reset_metrics(&self)
pub fn reset_metrics(&self)
Reset metrics - atomic operations
Sourcepub fn resize(&self, new_capacity: usize) -> Result<(), String>
pub fn resize(&self, new_capacity: usize) -> Result<(), String>
Resize cache capacity - atomic Resizes the cache to a new capacity
§Errors
Returns an error if new_capacity is 0 or if eviction fails during resize
Sourcepub fn has_performance_issues(&self) -> bool
pub fn has_performance_issues(&self) -> bool
Check for performance issues - atomic reads only
Sourcepub fn get_recommendations(&self) -> Vec<String>
pub fn get_recommendations(&self) -> Vec<String>
Get performance recommendations
Sourcepub fn drain_eviction_events(&self) -> Vec<EvictionEvent<K>>
pub fn drain_eviction_events(&self) -> Vec<EvictionEvent<K>>
Drain eviction events (for monitoring)
Trait Implementations§
Source§impl<K, V> CacheProvider for Cache<K, V>
impl<K, V> CacheProvider for Cache<K, V>
Source§fn get_stats(&self) -> CacheStats
fn get_stats(&self) -> CacheStats
Returns a snapshot of cache statistics
Source§fn reset_metrics(&self)
fn reset_metrics(&self)
Resets all metric counters to zero
Source§fn has_performance_issues(&self) -> bool
fn has_performance_issues(&self) -> bool
Returns true if the cache exhibits performance problems
Source§fn get_recommendations(&self) -> Vec<String>
fn get_recommendations(&self) -> Vec<String>
Returns actionable recommendations for improving cache performance
Auto Trait Implementations§
impl<K, V> !Freeze for Cache<K, V>
impl<K, V> !RefUnwindSafe for Cache<K, V>
impl<K, V> Send for Cache<K, V>
impl<K, V> Sync for Cache<K, V>
impl<K, V> Unpin for Cache<K, V>where
K: Unpin,
impl<K, V> UnsafeUnpin for Cache<K, V>
impl<K, V> UnwindSafe for Cache<K, V>where
K: UnwindSafe,
V: 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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request