pub struct GcraStore<C = SystemClock> { /* private fields */ }Expand description
A hard-bounded, process-local generic-cell-rate-algorithm store.
Each key occupies one constant-size entry. The store refuses to evict active entries, performs bounded cleanup per check, and preserves atomic all-or-nothing batches in caller order.
Implementations§
Source§impl GcraStore<SystemClock>
impl GcraStore<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> GcraStore<C>
impl<C: Clock> GcraStore<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.
Sourcepub fn with_observer(self, observer: Arc<dyn Observer>) -> Self
pub fn with_observer(self, observer: Arc<dyn Observer>) -> Self
Returns this store with an operational observer.
Sourcepub fn check(
&self,
check: &Check<'_, GcraPolicy>,
) -> Result<Decision, MemoryStoreError>
pub fn check( &self, check: &Check<'_, GcraPolicy>, ) -> Result<Decision, MemoryStoreError>
Evaluates and, when allowed, consumes one GCRA check.
§Errors
Fails closed when the target shard is poisoned or exact arithmetic cannot represent the caller-supplied clock value.
Sourcepub fn check_all(
&self,
checks: &[Check<'_, GcraPolicy>],
) -> Result<BatchDecision, MemoryStoreError>
pub fn check_all( &self, checks: &[Check<'_, GcraPolicy>], ) -> Result<BatchDecision, MemoryStoreError>
Evaluates an atomic batch of GCRA checks.
Allowed decisions preserve input order. A denied or shadow-denied batch consumes no quota.
§Errors
Fails closed for invalid batches, poisoned shards, an unsatisfiable per-shard batch, or arithmetic overflow.
Sourcepub fn stats(&self) -> Result<MemoryStoreStats, MemoryStoreError>
pub fn stats(&self) -> Result<MemoryStoreStats, MemoryStoreError>
Sourcepub fn clear(&self) -> Result<(), MemoryStoreError>
pub fn clear(&self) -> Result<(), MemoryStoreError>
Sourcepub fn recover_poisoned(&self) -> usize
pub fn recover_poisoned(&self) -> usize
Rebuilds poisoned shards by discarding their untrusted counter state.