pub trait ShrinkableKeyedStateStore<K: Hash>: KeyedStateStore<K> {
    // Required methods
    fn retain_recent(&self, drop_below: Nanos);
    fn len(&self) -> usize;
    fn is_empty(&self) -> bool;

    // Provided method
    fn shrink_to_fit(&self) { ... }
}
Expand description

Keyed rate limiters that can be “cleaned up”.

Any keyed state store implementing this trait allows users to evict elements that are indistinguishable from fresh rate-limiting states (that is, if a key hasn’t been used for rate-limiting decisions for as long as the bucket capacity).

As this does not make sense for not all keyed state stores (e.g. stores that auto-expire like memcache), this is an optional trait. All the keyed state stores in this crate implement shrinking.

Required Methods§

source

fn retain_recent(&self, drop_below: Nanos)

Remove those keys with state older than drop_below.

source

fn len(&self) -> usize

Returns the number of “live” keys stored in the state store.

Depending on how the state store is implemented, this may return an estimate or an out-of-date result.

source

fn is_empty(&self) -> bool

Returns true if self has no keys stored in it.

As with len, this method may return imprecise results (indicating that the state store is empty while a concurrent rate-limiting operation is taking place).

Provided Methods§

source

fn shrink_to_fit(&self)

Shrinks the capacity of the state store, if possible.

If the state store does not support shrinking, this method is a no-op.

Object Safety§

This trait is not object safe.

Implementors§