pub struct IdempotencyCache { /* private fields */ }Expand description
Request deduplication cache keyed on client-supplied idempotency keys.
When a client sends the same idempotency key twice, the second request
receives the cached response without re-executing the operation.
Entries expire after ttl and are lazily evicted.
Implementations§
Source§impl IdempotencyCache
impl IdempotencyCache
Sourcepub fn new(max_entries: usize, ttl: Duration) -> Self
pub fn new(max_entries: usize, ttl: Duration) -> Self
Create a new cache with the given capacity and TTL.
Sourcepub fn get(&self, key: &str) -> Option<(u16, Vec<u8>)>
pub fn get(&self, key: &str) -> Option<(u16, Vec<u8>)>
Look up a previously cached response by idempotency key.
Returns (status_code, body) if a fresh entry exists; None otherwise.
Sourcepub fn insert(&self, key: &str, status: u16, body: Vec<u8>)
pub fn insert(&self, key: &str, status: u16, body: Vec<u8>)
Store a response under the given idempotency key.
If the cache is full, expired entries are evicted first. If still full after eviction, the insert is silently dropped to prevent unbounded memory growth.
Sourcepub fn evict_expired(&self)
pub fn evict_expired(&self)
Remove all expired entries from the cache.
Auto Trait Implementations§
impl !Freeze for IdempotencyCache
impl RefUnwindSafe for IdempotencyCache
impl Send for IdempotencyCache
impl Sync for IdempotencyCache
impl Unpin for IdempotencyCache
impl UnsafeUnpin for IdempotencyCache
impl UnwindSafe for IdempotencyCache
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
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