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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more