pub struct SettlementCache { /* private fields */ }cache only.Expand description
Chain-agnostic deduplication cache for facilitator settlement requests.
Wraps TtlSet with the canonical x402 v2 TTL (DEFAULT_SETTLEMENT_TTL)
and capacity (DEFAULT_SETTLEMENT_CAPACITY). Used by every chain
crate to defend against duplicate / replayed /settle calls within
the on-chain replay window:
- EVM exact — keyed by
chain:nonce_hex(the EIP-3009 nonce binds one-shot to a single token + payer pair). - EVM upto — keyed by
chain:permit2_nonce_hex. - SVM exact — keyed by the base64 transaction payload.
The cache is in-memory only. A facilitator deployment that spans
multiple processes must either pin requests to a single worker or
replace this cache with a Redis-backed implementation by wiring its
own TtlSet-equivalent through the same trait surface.
Implementations§
Source§impl SettlementCache
impl SettlementCache
Sourcepub fn with_params(ttl: Duration, capacity: u64) -> Self
pub fn with_params(ttl: Duration, capacity: u64) -> Self
Constructs a cache with custom TTL and capacity.
Sourcepub fn reserve(&self, key: impl Into<String>) -> Duplicate
pub fn reserve(&self, key: impl Into<String>) -> Duplicate
Atomically reserves the key. Returns Duplicate::No when newly
inserted (caller may proceed) or Duplicate::Yes when the key
is already present (caller must abort with DuplicateSettlement).
Increments the
r402_settlement_cache_reserve_total
counter with outcome=inserted|duplicate when the metrics
feature is enabled.
Sourcepub fn entry_count(&self) -> u64
pub fn entry_count(&self) -> u64
Returns the approximate current entry count (observability hook).
Trait Implementations§
Source§impl Clone for SettlementCache
impl Clone for SettlementCache
Source§fn clone(&self) -> SettlementCache
fn clone(&self) -> SettlementCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more