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 moresource§impl Debug for EvictionPolicy
impl Debug for EvictionPolicy
source§impl Default for EvictionPolicy
impl Default for EvictionPolicy
source§fn default() -> EvictionPolicy
fn default() -> EvictionPolicy
Auto Trait Implementations§
impl Freeze for EvictionPolicy
impl RefUnwindSafe for EvictionPolicy
impl Send for EvictionPolicy
impl Sync for EvictionPolicy
impl Unpin for EvictionPolicy
impl UnwindSafe for EvictionPolicy
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)