pub struct InMemoryCache<T> { /* private fields */ }Expand description
In-memory cache with LRU eviction and TTL expiration
Implementations§
Source§impl<T: Clone + Send + Sync + 'static> InMemoryCache<T>
impl<T: Clone + Send + Sync + 'static> InMemoryCache<T>
Sourcepub fn new(config: DualCacheConfig) -> Self
pub fn new(config: DualCacheConfig) -> Self
Create a new in-memory cache with the given configuration
Sourcepub fn with_stats(config: DualCacheConfig, stats: Arc<AtomicCacheStats>) -> Self
pub fn with_stats(config: DualCacheConfig, stats: Arc<AtomicCacheStats>) -> Self
Create a new in-memory cache with shared statistics
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create with default configuration
Sourcepub fn start_cleanup_task(self: &Arc<Self>)
pub fn start_cleanup_task(self: &Arc<Self>)
Start the background cleanup task
Sourcepub async fn peek(&self, key: &CacheKey) -> Option<T>
pub async fn peek(&self, key: &CacheKey) -> Option<T>
Peek a value without recording hit/miss statistics.
Used for under-lock Dual L1 rechecks after an accounting miss so a single client lookup is not double-counted. Still updates eviction access meta on a live hit and still removes expired entries.
Sourcepub async fn get_entry(&self, key: &CacheKey) -> Option<CacheEntry<T>>
pub async fn get_entry(&self, key: &CacheKey) -> Option<CacheEntry<T>>
Get an entry with metadata from the cache
Sourcepub async fn peek_entry(&self, key: &CacheKey) -> Option<CacheEntry<T>>
pub async fn peek_entry(&self, key: &CacheKey) -> Option<CacheEntry<T>>
Peek an entry without recording hit/miss statistics (see Self::peek).
Sourcepub async fn set_with_ttl(&self, key: CacheKey, value: T, ttl: Duration)
pub async fn set_with_ttl(&self, key: CacheKey, value: T, ttl: Duration)
Set a value in the cache with a specific TTL
Sourcepub async fn set_with_size(
&self,
key: CacheKey,
value: T,
ttl: Duration,
size_bytes: usize,
)
pub async fn set_with_size( &self, key: CacheKey, value: T, ttl: Duration, size_bytes: usize, )
Set a value with size tracking
Sourcepub async fn delete_if<F>(&self, key: &CacheKey, predicate: F) -> Option<T>
pub async fn delete_if<F>(&self, key: &CacheKey, predicate: F) -> Option<T>
Atomically delete key only while the live (non-expired) value matches predicate.
Uses DashMap remove_if so a concurrent replacement under the same key is
not removed after a stale match decision. Bookkeeping removal checks live
state while holding the candidate-index lock, so a replacement inserted
after remove_if keeps its eviction metadata and candidate slot.
Returns the removed value when a matching entry was deleted.
Sourcepub fn stats(&self) -> Arc<AtomicCacheStats> ⓘ
pub fn stats(&self) -> Arc<AtomicCacheStats> ⓘ
Get cache statistics
Trait Implementations§
Source§impl<T> Drop for InMemoryCache<T>
impl<T> Drop for InMemoryCache<T>
Auto Trait Implementations§
impl<T> !Freeze for InMemoryCache<T>
impl<T> !RefUnwindSafe for InMemoryCache<T>
impl<T> !UnwindSafe for InMemoryCache<T>
impl<T> Send for InMemoryCache<T>
impl<T> Sync for InMemoryCache<T>
impl<T> Unpin for InMemoryCache<T>
impl<T> UnsafeUnpin for InMemoryCache<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
Source§impl<T> BudgetAwareRouting for T
impl<T> BudgetAwareRouting for T
Source§fn filter_by_budget(
&self,
providers: Vec<String>,
budget_router: &BudgetAwareRouter,
) -> Vec<String>
fn filter_by_budget( &self, providers: Vec<String>, budget_router: &BudgetAwareRouter, ) -> Vec<String>
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 more