Weighter

Trait Weighter 

Source
pub trait Weighter<K, V> {
    // Required method
    fn item_weight(&self, key: &K, value: &V) -> u64;
}
Expand description

Calculates the weight of cache items.

Required Methods§

Source

fn item_weight(&self, key: &K, value: &V) -> u64

Returns the weight of the cache item.

For performance reasons, this function should be as cheap as possible, as it will be called during the cache eviction routine. If the weight is expensive to calculate, consider caching it alongside the value.

Zero (0) weight items are allowed and will be ignored when looking for eviction candidates. Such items can only be manually removed or overwritten.

Implementors§

Source§

impl<K, V> Weighter<K, V> for ItemCountWeighter