Skip to main content

ThrottleStore

Trait ThrottleStore 

Source
pub trait ThrottleStore:
    Send
    + Sync
    + 'static {
    // Required methods
    fn incr(&self, key: String, ttl: Duration) -> BoxFuture<'_, Result<u64>>;
    fn count(&self, key: String) -> BoxFuture<'_, Result<u64>>;
}
Expand description

A backend that counts requests per key within a time window.

The throttler buckets each key by window and asks the store to count hits. An in-memory store (MemoryThrottleStore) suits a single instance; a Redis store (behind the redis feature) shares the count across instances.

Required Methods§

Source

fn incr(&self, key: String, ttl: Duration) -> BoxFuture<'_, Result<u64>>

Atomically increments the counter at key, setting it to expire after ttl when first created, and returns the new count.

Source

fn count(&self, key: String) -> BoxFuture<'_, Result<u64>>

Returns the current count at key without changing it (0 if absent or expired). Used by the sliding-window estimate to read the previous window.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§