Skip to main content

MemoryStore

Struct MemoryStore 

Source
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>

Source

pub fn new(config: MemoryStoreConfig) -> Self

Creates a store using the system monotonic clock.

Source§

impl<C: Clock> MemoryStore<C>

Source

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.

Source

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.

Source

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.

Source

pub fn stats(&self) -> Result<MemoryStoreStats, MemoryStoreError>

Returns current storage usage.

§Errors

Returns an error if a shard is poisoned.

Source

pub fn clear(&self) -> Result<(), MemoryStoreError>

Removes every stored counter.

§Errors

Returns an error if a shard is poisoned.

Auto Trait Implementations§

§

impl<C> Freeze for MemoryStore<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for MemoryStore<C>
where C: RefUnwindSafe,

§

impl<C> Send for MemoryStore<C>
where C: Send,

§

impl<C> Sync for MemoryStore<C>
where C: Sync,

§

impl<C> Unpin for MemoryStore<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for MemoryStore<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for MemoryStore<C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.