Trait light_cache::policy::Policy
source · pub trait Policy<K, V>: Clone {
type Inner: Prune<K, V, Self>;
// Required methods
fn lock_inner(&self) -> MutexGuard<'_, Self::Inner>;
fn get<S: BuildHasher>(
&self,
key: &K,
cache: &LightCache<K, V, S, Self>,
) -> Option<V>;
fn insert<S: BuildHasher>(
&self,
key: K,
value: V,
cache: &LightCache<K, V, S, Self>,
) -> Option<V>;
fn remove<S: BuildHasher>(
&self,
key: &K,
cache: &LightCache<K, V, S, Self>,
) -> Option<V>;
// Provided method
fn prune<S: BuildHasher>(&self, cache: &LightCache<K, V, S, Self>) { ... }
}Expand description
A Policy augments accsess to a LightCache instance, managing the entry and eviction of items in the cache.
A policy usally requires shared mutable state, therefore the Policy::Inner type is used to represent this.
Required Associated Types§
Required Methods§
sourcefn lock_inner(&self) -> MutexGuard<'_, Self::Inner>
fn lock_inner(&self) -> MutexGuard<'_, Self::Inner>
§Panics
This method will panic if the lock is poisoned
fn get<S: BuildHasher>( &self, key: &K, cache: &LightCache<K, V, S, Self>, ) -> Option<V>
fn insert<S: BuildHasher>( &self, key: K, value: V, cache: &LightCache<K, V, S, Self>, ) -> Option<V>
fn remove<S: BuildHasher>( &self, key: &K, cache: &LightCache<K, V, S, Self>, ) -> Option<V>
Provided Methods§
sourcefn prune<S: BuildHasher>(&self, cache: &LightCache<K, V, S, Self>)
fn prune<S: BuildHasher>(&self, cache: &LightCache<K, V, S, Self>)
§Warning:
Calling this method while holding a lock from Policy::lock_inner will cause a deadlock
Object Safety§
This trait is not object safe.