ezcache::thread_safe

Trait ThreadSafeCacheStore

Source
pub trait ThreadSafeCacheStore<'lock>
where Self: 'lock,
{ type Key; type Value; type SLock<'guard>: From<&'guard Self::XLock> where 'lock: 'guard; type XLock: 'lock; // Required methods fn ts_get(&'lock self, handle: &Self::SLock<'_>) -> Option<Self::Value>; fn ts_set(&'lock self, handle: &mut Self::XLock, value: &Self::Value); fn ts_xlock(&'lock self, key: &Self::Key) -> Self::XLock; fn ts_slock(&'lock self, key: &Self::Key) -> Self::SLock<'lock>; fn ts_xlock_nblock(&'lock self, key: &Self::Key) -> Self::XLock; fn ts_slock_nblock(&'lock self, key: &Self::Key) -> Self::SLock<'lock>; // Provided methods fn ts_exists(&'lock self, handle: &Self::SLock<'_>) -> bool { ... } fn ts_one_get(&'lock self, key: &Self::Key) -> Option<Self::Value> { ... } fn ts_one_set(&'lock self, key: &Self::Key, value: &Self::Value) { ... } fn ts_one_exists(&'lock self, key: &Self::Key) -> bool { ... } }
Expand description

Trait for a thread safe infallible cache store, analogous to CacheStore

Required Associated Types§

Source

type Key

Source

type Value

Source

type SLock<'guard>: From<&'guard Self::XLock> where 'lock: 'guard

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

Source

type XLock: 'lock

Exclusive lock over a wey.

Required Methods§

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_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.

Provided Methods§

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

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

Source§

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