pub struct TtlSet { /* private fields */ }cache only.Expand description
A Send+Sync cache of string keys with bounded capacity and TTL expiry.
Designed for deduplication / idempotency workloads: the reserve
method atomically inserts the key if absent, returning a Duplicate
discriminator. No value type is associated with each key — only presence
matters.
Backed by moka::sync::Cache internally; cloning shares the same
underlying storage thanks to moka’s internal Arc.
Implementations§
Source§impl TtlSet
impl TtlSet
Sourcepub fn new(ttl: Duration, max_capacity: u64) -> Self
pub fn new(ttl: Duration, max_capacity: u64) -> Self
Constructs a cache with the given TTL and maximum capacity.
Sourcepub fn reserve(&self, key: impl Into<String>) -> Duplicate
pub fn reserve(&self, key: impl Into<String>) -> Duplicate
Reserves a key: returns Duplicate::No if newly inserted,
Duplicate::Yes if already present.
This operation is lock-free and coalesces concurrent inserts of the
same key (exactly one insertion wins; others observe Yes).
Sourcepub fn contains(&self, key: &str) -> bool
pub fn contains(&self, key: &str) -> bool
Returns true if key is currently present in the cache.
Sourcepub fn entry_count(&self) -> u64
pub fn entry_count(&self) -> u64
Returns the approximate current entry count (used for observability).