pub struct TypedCache<V: Send + Sync + 'static> { /* private fields */ }Expand description
A type-erased, cloneable cache for values of type V.
Wraps any CacheBackend<V> behind an Arc<dyn …>, so it can be
cloned cheaply and stored in structs without generics leaking into the
public API.
The concrete backend is selected via CacheConfig::backend.
§Example
use pubmed_client::cache::{TypedCache, MemoryCache, CacheConfig};
let config = CacheConfig::default();
let cache: TypedCache<String> = TypedCache::new(MemoryCache::new(&config));
cache.insert("key".to_string(), "value".to_string()).await;
assert_eq!(cache.get("key").await, Some("value".to_string()));Implementations§
Source§impl<V: Send + Sync + 'static> TypedCache<V>
impl<V: Send + Sync + 'static> TypedCache<V>
Sourcepub fn new(backend: impl CacheBackend<V> + 'static) -> Self
pub fn new(backend: impl CacheBackend<V> + 'static) -> Self
Wrap backend in a TypedCache.
pub async fn get(&self, key: &str) -> Option<V>
pub async fn insert(&self, key: String, value: V)
pub async fn clear(&self)
pub fn entry_count(&self) -> u64
pub async fn sync(&self)
Trait Implementations§
Auto Trait Implementations§
impl<V> Freeze for TypedCache<V>
impl<V> !RefUnwindSafe for TypedCache<V>
impl<V> Send for TypedCache<V>
impl<V> Sync for TypedCache<V>
impl<V> Unpin for TypedCache<V>
impl<V> !UnwindSafe for TypedCache<V>
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