pub trait ShrinkableKeyedStateStore<K: Hash>: KeyedStateStore<K> {
    fn retain_recent(&self, drop_below: Nanos);
fn len(&self) -> usize;
fn is_empty(&self) -> bool; 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

Remove those keys with state older than drop_below.

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.

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

Shrinks the capacity of the state store, if possible.

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

Implementors