pub struct ResponseCache { /* private fields */ }Expand description
Thread-safe bounded LRU response cache.
Implementations§
Source§impl ResponseCache
impl ResponseCache
Sourcepub fn new(capacity: usize, ttl: Duration) -> ResponseCache
pub fn new(capacity: usize, ttl: Duration) -> ResponseCache
Creates a cache with the requested capacity and defaulting zero TTLs.
Capacity is clamped to the inclusive range 1..=512.
Sourcepub fn with_ttl(ttl: Duration) -> ResponseCache
pub fn with_ttl(ttl: Duration) -> ResponseCache
Creates a cache with the requested TTL and the maximum capacity.
Sourcepub fn set_policy(&mut self, policy: CachePolicy)
pub fn set_policy(&mut self, policy: CachePolicy)
Replaces the cache expiry policy for existing and future entries.
Sourcepub fn get(&self, key: &ResponseCacheKey) -> Option<CachedResponse>
pub fn get(&self, key: &ResponseCacheKey) -> Option<CachedResponse>
Looks up a response, refreshing its LRU position on a live hit.
Sourcepub fn put(&self, key: ResponseCacheKey, response: CachedResponse)
pub fn put(&self, key: ResponseCacheKey, response: CachedResponse)
Inserts or replaces a response, evicting the least recently used entry when the bounded capacity is reached.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Returns cumulative hit, miss, and eviction counters.
Trait Implementations§
Source§impl Debug for ResponseCache
impl Debug for ResponseCache
Source§impl Default for ResponseCache
impl Default for ResponseCache
Source§fn default() -> ResponseCache
fn default() -> ResponseCache
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for ResponseCache
impl Forget for ResponseCache
impl Move for ResponseCache
impl RefUnwindSafe for ResponseCachewhere
Mutex<CacheState>: RefUnwindSafe,
impl Send for ResponseCache
impl Sync for ResponseCache
impl Unpin for ResponseCache
impl UnsafeUnpin for ResponseCachewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<(String, Duration)>: UnsafeUnpin,
Align4<u32>: UnsafeUnpin,
Align1<u8>: UnsafeUnpin,
PhantomData<(ResponseCacheKey, CachedResponse)>: UnsafeUnpin,
PhantomData<(String, u64)>: UnsafeUnpin,
impl UnwindSafe for ResponseCache
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> 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