Skip to main content

MemoryBackend

Struct MemoryBackend 

Source
pub struct MemoryBackend<K, V> { /* private fields */ }
Expand description

An in-memory cache backend with an entry-count capacity.

Clones share the same storage. Independently constructed instances are isolated, including for CacheBackend::clear.

Implementations§

Source§

impl<K, V> MemoryBackend<K, V>
where K: Clone + Eq + Hash + Send + Sync + 'static, V: Send + Sync + 'static,

Source

pub fn new(max_capacity: u64) -> Self

Creates a backend capped at max_capacity entries.

Trait Implementations§

Source§

impl<K, V> CacheBackend<K, V> for MemoryBackend<K, V>
where K: Clone + Eq + Hash + Send + Sync + 'static, V: Send + Sync + 'static,

Source§

fn get<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 K, ) -> Pin<Box<dyn Future<Output = KapeResult<Option<CacheEntry<V>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Queries one key.
Source§

fn set<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 K, value: Arc<V>, ttl: i64, ) -> Pin<Box<dyn Future<Output = KapeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Stores or immediately invalidates one key using a millisecond TTL.
Source§

fn remove<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 K, ) -> Pin<Box<dyn Future<Output = KapeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Removes one key.
Source§

fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = KapeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clears entries owned by this backend instance.
Source§

fn get_many<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, keys: &'life1 [&'life2 K], ) -> Pin<Box<dyn Future<Output = Result<Vec<Option<CacheEntry<V>>>, KapeError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Queries multiple keys while preserving input order and duplicates.
Source§

fn set_many<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, items: &'life1 [SetItem<&'life2 K, V>], ) -> Pin<Box<dyn Future<Output = Result<(), KapeError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, K: Eq + Hash, Self: 'async_trait,

Writes multiple uniquely keyed items in input order.
Source§

fn remove_many<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, keys: &'life1 [&'life2 K], ) -> Pin<Box<dyn Future<Output = Result<(), KapeError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Removes multiple keys in input order.
Source§

impl<K, V> Clone for MemoryBackend<K, V>

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

Auto Trait Implementations§

§

impl<K, V> !RefUnwindSafe for MemoryBackend<K, V>

§

impl<K, V> !UnwindSafe for MemoryBackend<K, V>

§

impl<K, V> Freeze for MemoryBackend<K, V>
where Cache<K, MemoryEntry<V>>: Freeze,

§

impl<K, V> Send for MemoryBackend<K, V>
where Cache<K, MemoryEntry<V>>: Send,

§

impl<K, V> Sync for MemoryBackend<K, V>
where Cache<K, MemoryEntry<V>>: Sync,

§

impl<K, V> Unpin for MemoryBackend<K, V>
where Cache<K, MemoryEntry<V>>: Unpin,

§

impl<K, V> UnsafeUnpin for MemoryBackend<K, V>
where Cache<K, MemoryEntry<V>>: UnsafeUnpin,

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.