pub struct ApiResponseCache { /* private fields */ }Expand description
Thread-safe API response cache
Implementations§
Source§impl ApiResponseCache
impl ApiResponseCache
Sourcepub fn get_or_compute<F>(
&self,
key: &str,
ttl: Duration,
compute_fn: F,
) -> Result<(Arc<[u8]>, String), String>
pub fn get_or_compute<F>( &self, key: &str, ttl: Duration, compute_fn: F, ) -> Result<(Arc<[u8]>, String), String>
Get cached response or compute new one.
Optimized to return Arc<u8> instead of Vec
Sourcepub fn etag_matches(&self, key: &str, client_etag: &str) -> bool
pub fn etag_matches(&self, key: &str, client_etag: &str) -> bool
Check if client’s ETag matches (for 304 responses)
Sourcepub fn record_etag_hit(&self)
pub fn record_etag_hit(&self)
Record ETag hit (304 response sent)
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get current cache statistics
Trait Implementations§
Source§impl Clone for ApiResponseCache
impl Clone for ApiResponseCache
Source§impl Debug for ApiResponseCache
impl Debug for ApiResponseCache
Auto Trait Implementations§
impl Freeze for ApiResponseCache
impl RefUnwindSafe for ApiResponseCache
impl Send for ApiResponseCache
impl Sync for ApiResponseCache
impl Unpin for ApiResponseCache
impl UnsafeUnpin for ApiResponseCache
impl UnwindSafe for ApiResponseCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 more