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) -> Self
pub fn new(capacity: usize, ttl: Duration) -> Self
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) -> Self
pub fn with_ttl(ttl: Duration) -> Self
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
Auto Trait Implementations§
impl !Freeze for ResponseCache
impl RefUnwindSafe for ResponseCache
impl Send for ResponseCache
impl Sync for ResponseCache
impl Unpin for ResponseCache
impl UnsafeUnpin for ResponseCache
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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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