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§
Required Methods§
Sourcefn peek(&mut self, k: &Self::K) -> Option<Self::V>
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.
Sourcefn put(
&mut self,
k: Self::K,
v: Self::V,
) -> CachePolicyPutResult<Self::K, Self::V>
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
Sourcefn remove(&mut self, k: &Self::K) -> Option<Self::V>
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.