Skip to main content

MemoryCache

Struct MemoryCache 

Source
pub struct MemoryCache(/* private fields */);
Expand description

Clone shares one process-local cache. Separate new() calls are isolated.

Implementations§

Source§

impl MemoryCache

Source

pub fn new(options: MemoryOptions) -> Result<Self>

Source

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

Source§

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,

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.
Source§

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,

Source§

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,

None expects absence, including expiry. None replacement deletes.
Source§

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,

Source§

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,

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,

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.
Source§

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,

Source§

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,

Source§

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,

Returns after registration. Initial ResyncRequired ensures changes before registration are recovered by an authoritative reload.
Source§

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for MemoryCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.