pub struct SagaIdempotencyLru {
entries: VecDeque<((u64, CommandKind), Command)>,
cap: usize,
}Expand description
Idempotency LRU keyed by (saga_id, CommandKind). Stores the
resulting Report* Command so a duplicate dispatch re-emits the
same reply payload without re-running the action.
Implementation: simple VecDeque of (key, report) pairs. Front
is oldest, back is most-recent. Linear scan on lookup is fine at
cap=256: the entire scan is a few microseconds and only happens
once per saga command (a human-rate event).
Fields§
§entries: VecDeque<((u64, CommandKind), Command)>§cap: usizeImplementations§
Source§impl SagaIdempotencyLru
impl SagaIdempotencyLru
pub fn new(cap: usize) -> Self
pub fn with_default_cap() -> Self
Sourcepub fn get(&mut self, saga_id: u64, kind: CommandKind) -> Option<Command>
pub fn get(&mut self, saga_id: u64, kind: CommandKind) -> Option<Command>
Look up the cached Report for (saga_id, kind). On hit,
promotes the entry to most-recent (back of the deque) and
returns a clone of the cached Report. On miss, returns None.
Sourcepub fn insert(&mut self, saga_id: u64, kind: CommandKind, report: Command)
pub fn insert(&mut self, saga_id: u64, kind: CommandKind, report: Command)
Cache the Report for (saga_id, kind). If at capacity, drops
the oldest entry (front). If a duplicate key exists, updates
in place + promotes (defensive — caller usually hits via
get first; this branch covers a race where two duplicate
commands raced through get with both seeing miss).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SagaIdempotencyLru
impl RefUnwindSafe for SagaIdempotencyLru
impl Send for SagaIdempotencyLru
impl Sync for SagaIdempotencyLru
impl Unpin for SagaIdempotencyLru
impl UnwindSafe for SagaIdempotencyLru
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
§impl<T, U> ConvertReturnValue<U> for Twhere
T: Into<U>,
impl<T, U> ConvertReturnValue<U> for Twhere
T: Into<U>,
fn wrap_result(self) -> U
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.