pub struct SyncCache<K, V, C: Cache<K, V>> { /* private fields */ }Expand description
A thread-safe wrapper around any Cache implementation.
Wraps C (which implements Cache<K, V>) in a Mutex, providing
Send + Sync access from multiple threads. All methods acquire the
mutex for their duration.
§Panics
Every method panics if the inner mutex is poisoned, which happens when another thread panicked while holding the lock.
Implementations§
Source§impl<K, V, C: Cache<K, V>> SyncCache<K, V, C>
impl<K, V, C: Cache<K, V>> SyncCache<K, V, C>
Sourcepub fn get(&self, key: &K) -> Option<V>where
V: Clone,
pub fn get(&self, key: &K) -> Option<V>where
V: Clone,
Look up key, cloning and returning the value if present.
This acquires the lock, calls Cache::get (which may update
recency), and clones the result so the lock can be released.
Sourcepub fn put(&self, key: K, value: V) -> Option<V>
pub fn put(&self, key: K, value: V) -> Option<V>
Insert or update key -> value.
Returns the evicted value (if any) per the underlying cache policy.
Auto Trait Implementations§
impl<K, V, C> !Freeze for SyncCache<K, V, C>
impl<K, V, C> RefUnwindSafe for SyncCache<K, V, C>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, C> Send for SyncCache<K, V, C>
impl<K, V, C> Sync for SyncCache<K, V, C>
impl<K, V, C> Unpin for SyncCache<K, V, C>
impl<K, V, C> UnsafeUnpin for SyncCache<K, V, C>where
C: UnsafeUnpin,
impl<K, V, C> UnwindSafe for SyncCache<K, V, C>where
K: UnwindSafe,
V: UnwindSafe,
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