CachePolicy

Trait CachePolicy 

Source
pub trait CachePolicy:
    Debug
    + Send
    + 'static {
    type K: Clone + Eq + Hash + Ord + Debug + Send + 'static;
    type V: Clone + Debug + Send + 'static;

    // Required methods
    fn get(&mut self, k: &Self::K) -> Option<Self::V>;
    fn peek(&mut self, k: &Self::K) -> Option<Self::V>;
    fn put(
        &mut self,
        k: Self::K,
        v: Self::V,
    ) -> CachePolicyPutResult<Self::K, Self::V>;
    fn remove(&mut self, k: &Self::K) -> Option<Self::V>;
    fn pop(&mut self) -> Option<(Self::K, Self::V)>;
    fn as_any(&self) -> &dyn Any;
}

Required Associated Types§

Source

type K: Clone + Eq + Hash + Ord + Debug + Send + 'static

Cache key.

Source

type V: Clone + Debug + Send + 'static

Cached value.

Required Methods§

Source

fn get(&mut self, k: &Self::K) -> Option<Self::V>

Get value for given key if it exists.

Source

fn peek(&mut self, k: &Self::K) -> Option<Self::V>

Peek value for given key if it exists.

In contrast to get this will only return a value if there is a stored value. This will not change the cache entries.

Source

fn put( &mut self, k: Self::K, v: Self::V, ) -> CachePolicyPutResult<Self::K, Self::V>

Put value for given key.

If a key already exists, its old value will be returned.

At the meanwhile, entries popped due to memory pressure will be returned

Source

fn remove(&mut self, k: &Self::K) -> Option<Self::V>

Remove value for given key.

If a key does not exist, none will be returned.

Source

fn pop(&mut self) -> Option<(Self::K, Self::V)>

Remove an entry from the cache due to memory pressure or expiration.

If the cache is empty, none will be returned.

Source

fn as_any(&self) -> &dyn Any

Return backend as Any which can be used to downcast to a specific implementation.

Implementors§

Source§

impl<K, V, H> CachePolicy for LruCache<K, V, H>
where K: 'static + Clone + Debug + Eq + Hash + Ord + Send, H: 'static + BuildHasher + Debug + Send, V: 'static + Clone + Debug + Send,

Source§

type K = K

Source§

type V = V

Source§

impl<P> CachePolicy for CachePolicyWithListener<P>
where P: CachePolicy,

Source§

type K = <P as CachePolicy>::K

Source§

type V = <P as CachePolicy>::V