pub struct MemoryStore<C = SystemClock> { /* private fields */ }Expand description
A sharded, hard-bounded, process-local fixed-window store.
The store never evicts an active key to admit a new one. Every check touches only the shards required by that check and performs a bounded amount of expiry cleanup. An atomic batch locks its shards in deterministic order.
If application code panics while a shard is locked, that shard remains
poisoned and every later operation touching it fails closed with
MemoryStoreError::PoisonedShard. Replace the store explicitly rather
than automatically resetting quota for counters whose consistency is
unknown.
Implementations§
Source§impl MemoryStore<SystemClock>
impl MemoryStore<SystemClock>
Sourcepub fn new(config: MemoryStoreConfig) -> Self
pub fn new(config: MemoryStoreConfig) -> Self
Creates a store using the system monotonic clock.
Source§impl<C: Clock> MemoryStore<C>
impl<C: Clock> MemoryStore<C>
Sourcepub fn with_clock(config: MemoryStoreConfig, clock: C) -> Self
pub fn with_clock(config: MemoryStoreConfig, clock: C) -> Self
Creates a store using a caller-supplied monotonic clock.
Supplying a clock is primarily useful for deterministic tests.
Sourcepub fn check(&self, check: &Check<'_>) -> Result<Decision, MemoryStoreError>
pub fn check(&self, check: &Check<'_>) -> Result<Decision, MemoryStoreError>
Evaluates and, when allowed, consumes one check.
§Errors
Returns an error without allowing the request when the target shard is poisoned.
Sourcepub fn check_all(
&self,
checks: &[Check<'_>],
) -> Result<BatchDecision, MemoryStoreError>
pub fn check_all( &self, checks: &[Check<'_>], ) -> Result<BatchDecision, MemoryStoreError>
Evaluates a batch atomically.
If any check is denied, none of the checks consumes quota. Returned allowed decisions preserve input order.
§Errors
Returns an error before quota consumption when the batch exceeds its configured bound, contains a duplicate key, or a touched shard is poisoned.