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
fn retain_recent(&self, drop_below: Nanos)
fn retain_recent(&self, drop_below: Nanos)
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.
Provided methods
fn shrink_to_fit(&self)
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.