pub struct MemoryCache { /* private fields */ }Expand description
High-performance in-memory cache.
Uses a concurrent HashMap with LRU eviction and TTL support.
Implementations§
Source§impl MemoryCache
impl MemoryCache
Sourcepub fn new(config: MemoryCacheConfig) -> Self
pub fn new(config: MemoryCacheConfig) -> Self
Create a new memory cache with the given config.
Sourcepub fn builder() -> MemoryCacheBuilder
pub fn builder() -> MemoryCacheBuilder
Create a builder.
Sourcepub fn config(&self) -> &MemoryCacheConfig
pub fn config(&self) -> &MemoryCacheConfig
Get the config.
Sourcepub fn evict_expired(&self) -> usize
pub fn evict_expired(&self) -> usize
Evict expired entries.
Trait Implementations§
Source§impl CacheBackend for MemoryCache
impl CacheBackend for MemoryCache
Source§async fn get<T>(&self, key: &CacheKey) -> CacheResult<Option<T>>where
T: DeserializeOwned,
async fn get<T>(&self, key: &CacheKey) -> CacheResult<Option<T>>where
T: DeserializeOwned,
Get a value from the cache.
Source§async fn set<T>(
&self,
key: &CacheKey,
value: &T,
ttl: Option<Duration>,
) -> CacheResult<()>
async fn set<T>( &self, key: &CacheKey, value: &T, ttl: Option<Duration>, ) -> CacheResult<()>
Set a value in the cache.
Source§async fn invalidate_pattern(&self, pattern: &KeyPattern) -> CacheResult<u64>
async fn invalidate_pattern(&self, pattern: &KeyPattern) -> CacheResult<u64>
Invalidate entries matching a pattern.
Invalidate entries by tags.
Source§async fn clear(&self) -> CacheResult<()>
async fn clear(&self) -> CacheResult<()>
Clear all entries.
Source§async fn len(&self) -> CacheResult<usize>
async fn len(&self) -> CacheResult<usize>
Get the approximate number of entries.
Source§async fn stats(&self) -> CacheResult<BackendStats>
async fn stats(&self) -> CacheResult<BackendStats>
Get cache statistics if available.
Source§fn get_many<T>(
&self,
keys: &[CacheKey],
) -> impl Future<Output = CacheResult<Vec<Option<T>>>> + Sendwhere
T: DeserializeOwned + Send,
fn get_many<T>(
&self,
keys: &[CacheKey],
) -> impl Future<Output = CacheResult<Vec<Option<T>>>> + Sendwhere
T: DeserializeOwned + Send,
Get multiple values at once. Read more
Source§fn set_many<T>(
&self,
entries: &[(&CacheKey, &T)],
ttl: Option<Duration>,
) -> impl Future<Output = CacheResult<()>> + Send
fn set_many<T>( &self, entries: &[(&CacheKey, &T)], ttl: Option<Duration>, ) -> impl Future<Output = CacheResult<()>> + Send
Set multiple values at once. Read more
Source§fn delete_many(
&self,
keys: &[CacheKey],
) -> impl Future<Output = CacheResult<u64>> + Send
fn delete_many( &self, keys: &[CacheKey], ) -> impl Future<Output = CacheResult<u64>> + Send
Delete multiple keys at once. Read more
Auto Trait Implementations§
impl !Freeze for MemoryCache
impl !RefUnwindSafe for MemoryCache
impl Send for MemoryCache
impl Sync for MemoryCache
impl Unpin for MemoryCache
impl UnwindSafe for MemoryCache
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