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>
withV
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>
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
Sourcepub fn new(store: S, generator: F) -> Self
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>,
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>,
type Key = <S as ThreadSafeCacheStore<'lock>>::Key
type Value = <S as ThreadSafeCacheStore<'lock>>::Value
Source§type SLock<'guard> = <S as ThreadSafeCacheStore<'lock>>::SLock<'guard>
where
'lock: 'guard
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
type XLock = <S as ThreadSafeCacheStore<'lock>>::XLock
Exclusive lock over a wey.
Source§fn ts_get(&'lock self, handle: &Self::SLock<'_>) -> Option<Self::Value>
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)
fn ts_set(&'lock self, handle: &mut Self::XLock, value: &Self::Value)
Sets a value given its key.
Source§fn ts_one_get(&'lock self, key: &Self::Key) -> Option<Self::Value>
fn ts_one_get(&'lock self, key: &Self::Key) -> Option<Self::Value>
Same as
ts_get
but it performs a one-time lockSource§fn ts_one_set(&'lock self, key: &Self::Key, value: &Self::Value)
fn ts_one_set(&'lock self, key: &Self::Key, value: &Self::Value)
Same as
ts_set
but it performs a one-time lockSource§fn ts_one_exists(&'lock self, key: &Self::Key) -> bool
fn ts_one_exists(&'lock self, key: &Self::Key) -> bool
Same as
ts_exists
but it performs a one-time lockSource§fn ts_xlock(&'lock self, key: &Self::Key) -> Self::XLock
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>
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
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>
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>
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>
Implement ThreadSafeCacheStore
type Key = K
type Value = V
type Args = A
Source§fn ts_gen(
&'lock self,
key: &'lock <Self as ThreadSafeGenCacheStore<'lock>>::Key,
args: Self::Args,
) -> <Self as ThreadSafeGenCacheStore<'lock>>::Value
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
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
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
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>
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>
impl<'lock, K, V, A, S, F> Sync for ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>
impl<'lock, K, V, A, S, F> Unpin for ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>
impl<'lock, K, V, A, S, F> UnwindSafe for ThreadSafeGenCacheStoreWrapper<'lock, K, V, A, S, F>
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
Source§impl<'lock, K, V, SL, XL, T> ThreadSafeTryCacheStore<'lock> for Twhere
SL: for<'b> From<&'b XL> + 'lock,
XL: 'lock,
T: ThreadSafeCacheStore<'lock, Key = K, Value = V, SLock<'lock> = SL, XLock = XL>,
impl<'lock, K, V, SL, XL, T> ThreadSafeTryCacheStore<'lock> for Twhere
SL: for<'b> From<&'b XL> + 'lock,
XL: 'lock,
T: ThreadSafeCacheStore<'lock, Key = K, Value = V, SLock<'lock> = SL, XLock = XL>,
type Key = K
type Value = V
Source§type SLock<'guard> = SL
where
'lock: 'guard
type SLock<'guard> = SL where 'lock: 'guard
Shared lock over a key, must be possible to make one by borrowing a exclusive lock.
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>
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>
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>
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>
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>
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>
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>
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>
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