ezcache::thread_safe::generative

Struct ThreadSafeGenCacheStoreWrapper

Source
pub struct ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S: ThreadSafeCacheStore<'lock, Key = K, Value = V>, F: Fn(&K, A) -> V + 'lock> {
    pub store: S,
    pub generator: F,
    /* private fields */
}
Expand description

Infallible thread safe generative cache store wrapper around a ThreadSafeCacheStore and a generator function.

One of the few unafallible thread safe wrappers.

Generics:

  • K: Type of the key used for cache indexing.
  • V: Type of the value stored in the cache store.
  • A: Type of additional arguments of the generator function.
  • S: ThreadSafeCacheStore which this wraps around.
  • F: Fn<&K, A> with V return generator function.

Fields§

§store: S§generator: F

Implementations§

Source§

impl<'lock, K, V, A, S: ThreadSafeCacheStore<'lock, Key = K, Value = V>, F: Fn(&K, A) -> V> ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>

Default implementation

Source

pub fn new(store: S, generator: F) -> Self

Make a new ThreadSafeGenCacheStoreWrapper from a ThreadSafeCacheStore and a generator function.

Trait Implementations§

Source§

impl<'lock, K, V, A, S, F: Fn(&K, A) -> V + 'lock> ThreadSafeCacheStore<'lock> for ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>
where S: ThreadSafeCacheStore<'lock> + ThreadSafeCacheStore<'lock, Key = K, Value = V>,

Source§

type Key = <S as ThreadSafeCacheStore<'lock>>::Key

Source§

type Value = <S as ThreadSafeCacheStore<'lock>>::Value

Source§

type SLock<'guard> = <S as ThreadSafeCacheStore<'lock>>::SLock<'guard> where 'lock: 'guard

Shared lock over a key, must be possible to make one by borrowing a exclusive lock.
Source§

type XLock = <S as ThreadSafeCacheStore<'lock>>::XLock

Exclusive lock over a wey.
Source§

fn ts_get(&'lock self, handle: &Self::SLock<'_>) -> Option<Self::Value>

Returns an option of the owned cache element if present.
Source§

fn ts_set(&'lock self, handle: &mut Self::XLock, value: &Self::Value)

Sets a value given its key.
Source§

fn ts_exists(&'lock self, handle: &Self::SLock<'_>) -> bool

Checks if the cache entry exists.
Source§

fn ts_one_get(&'lock self, key: &Self::Key) -> Option<Self::Value>

Same as ts_get but it performs a one-time lock
Source§

fn ts_one_set(&'lock self, key: &Self::Key, value: &Self::Value)

Same as ts_set but it performs a one-time lock
Source§

fn ts_one_exists(&'lock self, key: &Self::Key) -> bool

Same as ts_exists but it performs a one-time lock
Source§

fn ts_xlock(&'lock self, key: &Self::Key) -> Self::XLock

Exclusively lock a key until the handle is dropped.
Source§

fn ts_slock(&'lock self, key: &Self::Key) -> Self::SLock<'lock>

Acquire a shared lock of a key until the handle is dropped.
Source§

fn ts_xlock_nblock(&'lock self, key: &Self::Key) -> Self::XLock

Exclusively lock a key until the handle is dropped. Non blocking.
Source§

fn ts_slock_nblock(&'lock self, key: &Self::Key) -> Self::SLock<'lock>

Acquire a shared lock of a key until the handle is dropped. Non blocking.
Source§

impl<'lock, K, V: Clone, A, S: ThreadSafeCacheStore<'lock, Key = K, Value = V>, F: Fn(&K, A) -> V> ThreadSafeGenCacheStore<'lock> for ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>

Source§

type Key = K

Source§

type Value = V

Source§

type Args = A

Source§

fn ts_gen( &'lock self, key: &'lock <Self as ThreadSafeGenCacheStore<'lock>>::Key, args: Self::Args, ) -> <Self as ThreadSafeGenCacheStore<'lock>>::Value

Generate a new value without checking cache or adding the value to it.
Source§

fn ts_get_or_gen( &'lock self, key: &'lock <Self as ThreadSafeGenCacheStore<'lock>>::Key, args: Self::Args, ) -> <Self as ThreadSafeGenCacheStore<'lock>>::Value

Get the value from cache or generate a new one without adding it.
Source§

fn ts_get_or_new( &'lock self, key: &'lock <Self as ThreadSafeGenCacheStore<'lock>>::Key, args: Self::Args, ) -> <Self as ThreadSafeGenCacheStore<'lock>>::Value

Get the value from cache or generate a new one adding it.
Source§

fn ts_gen_new( &'lock self, key: &'lock <Self as ThreadSafeGenCacheStore<'lock>>::Key, args: Self::Args, ) -> <Self as ThreadSafeGenCacheStore<'lock>>::Value

Generate a new value without checking cache and add the value to it, possibly overwriting previous values.

Auto Trait Implementations§

§

impl<'lock, K, V, A, S, F> Freeze for ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>
where S: Freeze, F: Freeze,

§

impl<'lock, K, V, A, S, F> RefUnwindSafe for ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>

§

impl<'lock, K, V, A, S, F> Send for ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>
where S: Send, F: Send, K: Sync, V: Sync, A: Sync,

§

impl<'lock, K, V, A, S, F> Sync for ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>
where S: Sync, F: Sync, K: Sync, V: Sync, A: Sync,

§

impl<'lock, K, V, A, S, F> Unpin for ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>
where S: Unpin, F: Unpin,

§

impl<'lock, K, V, A, S, F> UnwindSafe for ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>

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

Source§

type Output = T

Should always be Self
Source§

impl<'lock, K, V, SL, XL, T> ThreadSafeTryCacheStore<'lock> for T
where SL: for<'b> From<&'b XL> + 'lock, XL: 'lock, T: ThreadSafeCacheStore<'lock, Key = K, Value = V, SLock<'lock> = SL, XLock = XL>,

Source§

type Key = K

Source§

type Value = V

Source§

type SLock<'guard> = SL where 'lock: 'guard

Shared lock over a key, must be possible to make one by borrowing a exclusive lock.
Source§

type XLock = XL

Exclusive lock over a wey.
Source§

type Error = ()

Source§

fn ts_try_get( &'lock self, handle: &<T as ThreadSafeTryCacheStore<'lock>>::SLock<'lock>, ) -> Result<Option<<T as ThreadSafeTryCacheStore<'lock>>::Value>, <T as ThreadSafeTryCacheStore<'lock>>::Error>

Attempts to return an option of the owned cache element if present.
Source§

fn ts_try_set( &'lock self, handle: &mut <T as ThreadSafeTryCacheStore<'lock>>::XLock, value: &<T as ThreadSafeTryCacheStore<'lock>>::Value, ) -> Result<(), <T as ThreadSafeTryCacheStore<'lock>>::Error>

Attempts to set a value given its key.
Source§

fn ts_try_exists( &'lock self, handle: &<T as ThreadSafeTryCacheStore<'lock>>::SLock<'lock>, ) -> Result<bool, <T as ThreadSafeTryCacheStore<'lock>>::Error>

Attempts to check if the cache key entry exists.
Source§

fn ts_try_slock( &'lock self, key: &'lock <T as ThreadSafeTryCacheStore<'lock>>::Key, ) -> Result<<T as ThreadSafeTryCacheStore<'lock>>::SLock<'lock>, <T as ThreadSafeTryCacheStore<'lock>>::Error>

Attempt to acquire a shared lock of a key until the handle is dropped.
Source§

fn ts_try_xlock( &'lock self, key: &'lock <T as ThreadSafeTryCacheStore<'lock>>::Key, ) -> Result<<T as ThreadSafeTryCacheStore<'lock>>::XLock, <T as ThreadSafeTryCacheStore<'lock>>::Error>

Attempt to exclusively lock a key until the handle is dropped.
Source§

fn ts_try_slock_nblock( &'lock self, key: &'lock <T as ThreadSafeTryCacheStore<'lock>>::Key, ) -> Result<<T as ThreadSafeTryCacheStore<'lock>>::SLock<'lock>, <T as ThreadSafeTryCacheStore<'lock>>::Error>

Attempt to acquire a shared lock of a key until the handle is dropped. Non block.
Source§

fn ts_try_xlock_nblock( &'lock self, key: &'lock <T as ThreadSafeTryCacheStore<'lock>>::Key, ) -> Result<<T as ThreadSafeTryCacheStore<'lock>>::XLock, <T as ThreadSafeTryCacheStore<'lock>>::Error>

Attempt to exclusively lock a key until the handle is dropped. Non block.
Source§

fn ts_one_try_get( &'lock self, key: &'lock Self::Key, ) -> Result<Option<Self::Value>, Self::Error>

Same as ts_get but it performs a one-time lock
Source§

fn ts_one_try_set( &'lock self, key: &'lock Self::Key, value: &Self::Value, ) -> Result<(), Self::Error>

Same as ts_set but it performs a one-time lock
Source§

fn ts_one_try_exists( &'lock self, key: &'lock Self::Key, ) -> Result<bool, Self::Error>

Same as ts_exists but it performs a one-time lock
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.