pub struct MemoryCache(/* private fields */);Expand description
Clone shares one process-local cache. Separate new() calls are isolated.
Implementations§
Source§impl MemoryCache
impl MemoryCache
pub fn new(options: MemoryOptions) -> Result<Self>
Sourcepub fn purge_expired(&self) -> Result<usize>
pub fn purge_expired(&self) -> Result<usize>
Optional maintenance; expiry is always enforced on access. No background task.
Trait Implementations§
Source§impl Cache for MemoryCache
impl Cache for MemoryCache
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Entry>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn get_many<'life0, 'life1, 'async_trait>(
&'life0 self,
keys: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Entry>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_many<'life0, 'life1, 'async_trait>(
&'life0 self,
keys: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<Entry>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
get for each key, answered in the order asked. Each key is read
atomically on its own, exactly as get reads it; the batch is not a
snapshot across keys. It exists so a caller that needs many keys at
once pays one lock, round trip or query instead of one per key.fn put<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: Vec<u8>,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<Version>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn compare_exchange<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
expected: Option<Version>,
replacement: Option<Replacement>,
) -> Pin<Box<dyn Future<Output = Result<CasOutcome>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn compare_exchange<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
expected: Option<Version>,
replacement: Option<Replacement>,
) -> Pin<Box<dyn Future<Output = Result<CasOutcome>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
None expects absence, including expiry. None replacement deletes.
fn counter<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Counter>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn increment<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
amount: u64,
limit: u64,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<IncrementOutcome>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn decrement<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
generation: Version,
amount: u64,
) -> Pin<Box<dyn Future<Output = Result<Option<Counter>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn decrement<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
generation: Version,
amount: u64,
) -> Pin<Box<dyn Future<Output = Result<Option<Counter>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Generation check prevents a late decrement touching a new window.
This is not an idempotent receipt: the caller must release each charge
once and must not blindly retry after an ambiguous transport failure.
Source§fn acquire_permit<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
limit: u32,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<Option<Version>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn acquire_permit<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
limit: u32,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<Option<Version>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Expiring concurrency permit. Use limit=1 for a refresh lease. All callers
for a resource must use the same limit. No automatic renewal is performed.
fn renew_permit<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
owner: Version,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn release_permit<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
owner: Version,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn publish<'life0, 'life1, 'async_trait>(
&'life0 self,
topic: &'life1 str,
payload: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn subscribe<'life0, 'life1, 'async_trait>(
&'life0 self,
topic: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Subscription>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe<'life0, 'life1, 'async_trait>(
&'life0 self,
topic: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Subscription>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Returns after registration. Initial ResyncRequired ensures changes
before registration are recovered by an authoritative reload.
fn acquire_lease<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<Option<Version>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl Clone for MemoryCache
impl Clone for MemoryCache
Auto Trait Implementations§
impl Forget for MemoryCache
impl Freeze for MemoryCache
impl RefUnwindSafe for MemoryCache
impl Send for MemoryCache
impl Sync for MemoryCache
impl Unpin for MemoryCache
impl UnsafeUnpin 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