pub struct CacheAside<S> { /* private fields */ }Expand description
High-level cache-aside client with singleflight and negative caching.
Implementations§
Source§impl<S> CacheAside<S>
impl<S> CacheAside<S>
Sourcepub fn new(store: S, config: CacheAsideConfig) -> Self
pub fn new(store: S, config: CacheAsideConfig) -> Self
Creates a cache-aside helper around the given store.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Returns shared cache statistics.
Sourcepub fn with_metrics(self, metrics: MetricsRegistry) -> Self
pub fn with_metrics(self, metrics: MetricsRegistry) -> Self
Attaches a metrics registry to this cache-aside helper.
Source§impl<S> CacheAside<S>where
S: CacheStore,
impl<S> CacheAside<S>where
S: CacheStore,
Sourcepub async fn delete(&self, key: &CacheKey) -> CacheResult<()>
pub async fn delete(&self, key: &CacheKey) -> CacheResult<()>
Deletes a cached value and records delete failures in shared stats.
Sourcepub async fn get_or_load_json<T, F, Fut>(
&self,
key: &CacheKey,
loader: F,
) -> CacheResult<Option<T>>where
T: DeserializeOwned + Serialize + Send + Sync,
F: FnOnce() -> Fut + Send,
Fut: Future<Output = CacheResult<Option<T>>> + Send,
pub async fn get_or_load_json<T, F, Fut>(
&self,
key: &CacheKey,
loader: F,
) -> CacheResult<Option<T>>where
T: DeserializeOwned + Serialize + Send + Sync,
F: FnOnce() -> Fut + Send,
Fut: Future<Output = CacheResult<Option<T>>> + Send,
Reads JSON from cache or loads it once for concurrent misses.
Trait Implementations§
Source§impl<S: Clone> Clone for CacheAside<S>
impl<S: Clone> Clone for CacheAside<S>
Source§fn clone(&self) -> CacheAside<S>
fn clone(&self) -> CacheAside<S>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<S> Freeze for CacheAside<S>where
S: Freeze,
impl<S> !RefUnwindSafe for CacheAside<S>
impl<S> Send for CacheAside<S>where
S: Send,
impl<S> Sync for CacheAside<S>where
S: Sync,
impl<S> Unpin for CacheAside<S>where
S: Unpin,
impl<S> UnsafeUnpin for CacheAside<S>where
S: UnsafeUnpin,
impl<S> !UnwindSafe for CacheAside<S>
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,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request