pub struct InMemoryCacheProvider { /* private fields */ }
Expand description
In-memory cache provider
Uses LRU cache when “cache” feature is enabled, otherwise uses a simple HashMap.
Implementations§
Source§impl InMemoryCacheProvider
impl InMemoryCacheProvider
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new in-memory cache provider with specified capacity
Sourcepub fn with_default_capacity() -> Self
pub fn with_default_capacity() -> Self
Create a new cache provider with default capacity (1000 items)
Trait Implementations§
Source§impl CacheProvider for InMemoryCacheProvider
impl CacheProvider for InMemoryCacheProvider
Source§fn get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
key: &'life1 (impl 'async_trait + CacheKey),
) -> Pin<Box<dyn Future<Output = Option<T>> + Send + 'async_trait>>where
T: DeserializeOwned + Send + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
key: &'life1 (impl 'async_trait + CacheKey),
) -> Pin<Box<dyn Future<Output = Option<T>> + Send + 'async_trait>>where
T: DeserializeOwned + Send + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get a value from the cache
Source§fn set<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
key: &'life1 (impl 'async_trait + CacheKey),
value: &'life2 T,
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
fn set<'life0, 'life1, 'life2, 'async_trait, T>( &'life0 self, key: &'life1 (impl 'async_trait + CacheKey), value: &'life2 T, ttl: Option<Duration>, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
Set a value in the cache with optional TTL
Source§fn remove<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 (impl 'async_trait + CacheKey),
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remove<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 (impl 'async_trait + CacheKey),
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Remove a value from the cache
Source§fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Clear all values from the cache
Source§fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 (impl 'async_trait + CacheKey),
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 (impl 'async_trait + CacheKey),
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Check if a key exists in the cache
Source§fn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheStats> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheStats> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get cache statistics
Source§fn set_enabled(&mut self, enabled: bool)
fn set_enabled(&mut self, enabled: bool)
Set cache enabled/disabled state
Source§fn is_enabled(&self) -> bool
fn is_enabled(&self) -> bool
Check if cache is enabled
Auto Trait Implementations§
impl Freeze for InMemoryCacheProvider
impl RefUnwindSafe for InMemoryCacheProvider
impl Send for InMemoryCacheProvider
impl Sync for InMemoryCacheProvider
impl Unpin for InMemoryCacheProvider
impl UnwindSafe for InMemoryCacheProvider
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