pub struct MemoryCache { /* private fields */ }Expand description
Lean in-process cache store adapter for local development and tests.
Implementations§
Source§impl MemoryCache
impl MemoryCache
Sourcepub fn new(prefix: Option<String>, max_entries: Option<usize>) -> Self
pub fn new(prefix: Option<String>, max_entries: Option<usize>) -> Self
Create an empty in-memory cache.
Sourcepub fn new_with_clock(
prefix: Option<String>,
max_entries: Option<usize>,
clock: impl Fn() -> Instant + Send + Sync + 'static,
) -> Self
pub fn new_with_clock( prefix: Option<String>, max_entries: Option<usize>, clock: impl Fn() -> Instant + Send + Sync + 'static, ) -> Self
Create an in-memory cache with an injected clock.
This is primarily useful for deterministic tests and simulations that need to advance cache expiry without sleeping.
Trait Implementations§
Source§impl CacheStore for MemoryCache
impl CacheStore for MemoryCache
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = AppResult<Option<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = AppResult<Option<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Retrieve a string value by key.
Source§fn set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
val: &'life2 str,
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = AppResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
val: &'life2 str,
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = AppResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Store a string value with an optional TTL. Read more
Auto Trait Implementations§
impl !Freeze for MemoryCache
impl !RefUnwindSafe for MemoryCache
impl !UnwindSafe for MemoryCache
impl Send for MemoryCache
impl Sync for MemoryCache
impl Unpin for MemoryCache
impl UnsafeUnpin 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