Struct moka::policy::EvictionPolicy
source · pub struct EvictionPolicy { /* private fields */ }
Expand description
The eviction (and admission) policy of a cache.
When the cache is full, the eviction/admission policy is used to determine which items should be admitted to the cache and which cached items should be evicted. The choice of a policy will directly affect the performance (hit rate) of the cache.
The following policies are available:
- TinyLFU (default):
- Suitable for most workloads.
- TinyLFU combines the LRU eviction policy and an admission policy based on the historical popularity of keys.
- Note that it tracks not only the keys currently in the cache, but all hit and missed keys. The data structure used to estimate the popularity of keys is a modified Count-Min Sketch, which has a very low memory footprint (thus the name “tiny”).
- LRU:
- Suitable for some workloads with strong recency bias, such as streaming data processing.
LFU stands for Least Frequently Used. LRU stands for Least Recently Used.
Use associate function EvictionPolicy::tiny_lfu
or
EvictionPolicy::lru
to obtain an instance of EvictionPolicy
.
Implementations§
source§impl EvictionPolicy
impl EvictionPolicy
sourcepub fn tiny_lfu() -> Self
pub fn tiny_lfu() -> Self
Returns the TinyLFU policy, which is suitable for most workloads.
TinyLFU is a combination of the LRU eviction policy and the admission policy based on the historical popularity of keys.
Note that it tracks not only the keys currently in the cache, but all hit and missed keys. The data structure used to estimate the popularity of keys is a modified Count-Min Sketch, which has a very low memory footprint (thus the name “tiny”).
Trait Implementations§
source§impl Clone for EvictionPolicy
impl Clone for EvictionPolicy
source§fn clone(&self) -> EvictionPolicy
fn clone(&self) -> EvictionPolicy
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more