pub struct MokaCache { /* private fields */ }Expand description
Byte-weighed TTL cache over moka (DW-037 response-cache backend).
Bounds, honestly stated:
- Bytes, not entries:
max_capacityis interpreted through a weigher counting key + value bytes plus a fixed per-entry overhead (ENTRY_OVERHEAD_BYTES), so the store is bounded by MEMORY, the property a gateway cache actually needs (entry-count bounds let N one-byte-below-the-cap entries allocate N times the cap). - Time-to-idle (
MokaCache::TIME_TO_IDLE): entries nobody looks at for an hour are evicted even when still nominally fresh — a cold entry costs memory and a future miss, nothing else. - Per-entry TTL via
CacheStore::set_with_ttl: the hint rides the stored pair and drives moka’sExpirypolicy (plus 60 s of slack over the hint, so the envelope’s read-side expiry always fires first and the backend only reclaims what the policy already abandoned).
All eviction (size, idle, TTL) is approximate and concurrent — moka maintains shards internally; no global lock sits on the hot path.
Implementations§
Trait Implementations§
Source§impl CacheStore for MokaCache
impl CacheStore for MokaCache
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, ExtensionsError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, ExtensionsError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Fetch the value for
key, if present.Source§fn set<'life0, 'async_trait>(
&'life0 self,
key: String,
value: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<(), ExtensionsError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set<'life0, 'async_trait>(
&'life0 self,
key: String,
value: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<(), ExtensionsError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Store
value under key, overwriting any previous value.Source§fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, ExtensionsError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, ExtensionsError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Remove
key; returns whether a value existed.Source§fn set_with_ttl<'life0, 'async_trait>(
&'life0 self,
key: String,
value: Vec<u8>,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), ExtensionsError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_with_ttl<'life0, 'async_trait>(
&'life0 self,
key: String,
value: Vec<u8>,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), ExtensionsError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Store
value under key with a per-entry lifetime hint
(DW-037). Backends that cannot honor a per-entry TTL implement
the default (store without the hint); every reader re-checks
expiry from the value itself, so correctness never depends on
this. Defaulted, not abstract: existing implementations stay
valid backends without a change (extend, do not break).Source§fn entry_count(&self) -> Option<u64>
fn entry_count(&self) -> Option<u64>
Approximate number of live entries, when the backend can report
it cheaply (DW-037 metrics gauge; None = not reportable). An
estimate is acceptable — the consumer renders it as a gauge.
Auto Trait Implementations§
impl Freeze for MokaCache
impl !RefUnwindSafe for MokaCache
impl Send for MokaCache
impl Sync for MokaCache
impl Unpin for MokaCache
impl !UnwindSafe for MokaCache
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
Attempts to downcast this to
T behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
Attempts to downcast this to
T behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
Attempts to downcast this to
T behind Rc pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
Attempts to downcast this to
T behind Arc pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
Attempts to downcast this to
T behind Box pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Attempts to downcast owned
Self to T,
useful only in generic context as a workaround for specializationSource§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<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> ServiceExt for T
impl<T> ServiceExt for T
§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Apply a transformation to the response body. Read more
§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using HTTP status codes. Read more
§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using gRPC headers. Read more