Skip to main content

Module sync

Module sync 

Source
Expand description

Thread-safe cache wrapper — wraps any Cache impl behind a Mutex. Thread-safe cache wrapper backed by a std::sync::Mutex.

SyncCache wraps any Cache implementation and provides a Send + Sync interface suitable for sharing between threads. The internal mutex is a standard library Mutex, so poisoning is reported as a panic — a poisoned mutex indicates a bug (panic) in another thread, not a recoverable error.

§Example

use oxistore_cache::{LruCache, SyncCache};
use std::sync::Arc;

let cache = Arc::new(SyncCache::new(LruCache::<i32, i32>::new(100)));
cache.put(1, 42);
assert_eq!(cache.get(&1), Some(42));

Structs§

SyncCache
A thread-safe wrapper around any Cache implementation.