pub struct TtlCache<T> { /* private fields */ }Expand description
String-keyed cache where hits and misses expire on independent TTLs.
A TTL of zero disables caching for that outcome kind. lock_for hands out
a per-key async mutex so concurrent fetchers of the same key collapse into
one upstream request.
Implementations§
Source§impl<T: Clone> TtlCache<T>
impl<T: Clone> TtlCache<T>
pub fn new(positive_ttl: Duration, negative_ttl: Duration) -> Self
pub fn set_ttls(&self, positive_ttl: Duration, negative_ttl: Duration)
pub fn positive_ttl(&self) -> Duration
pub fn negative_ttl(&self) -> Duration
Sourcepub fn read(&self, key: &str) -> Option<Cached<T>>
pub fn read(&self, key: &str) -> Option<Cached<T>>
Read a live entry, honouring the current TTL configuration.
Expired entries are evicted. Hits are returned only when the positive TTL is non-zero; misses only when the negative TTL is non-zero.
Sourcepub fn write_hit(&self, key: String, value: T)
pub fn write_hit(&self, key: String, value: T)
Store a hit under the positive TTL. No-op when the TTL is zero.
Sourcepub fn write_miss(&self, key: String, detail: String)
pub fn write_miss(&self, key: String, detail: String)
Store a miss under the negative TTL. No-op when the TTL is zero.
Auto Trait Implementations§
impl<T> !Freeze for TtlCache<T>
impl<T> RefUnwindSafe for TtlCache<T>
impl<T> Send for TtlCache<T>where
T: Send,
impl<T> Sync for TtlCache<T>where
T: Send,
impl<T> Unpin for TtlCache<T>where
T: Unpin,
impl<T> UnsafeUnpin for TtlCache<T>
impl<T> UnwindSafe for TtlCache<T>
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