Trait governor::state::keyed::ShrinkableKeyedStateStore
source · 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§
sourcefn retain_recent(&self, drop_below: Nanos)
fn retain_recent(&self, drop_below: Nanos)
Remove those keys with state older than drop_below
.
Provided Methods§
sourcefn 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.
Object Safety§
This trait is not object safe.