Policy

Trait Policy 

Source
pub trait Policy<K, V>: Sized {
    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 lock_and_prune<S: BuildHasher>(
        &self,
        cache: &LightCache<K, V, S, Self>,
    ) -> MutexGuard<'_, Self::Inner> { ... }
}
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§

Source

type Inner: Prune<K, V, Self>

The inner type of this policy, likely behind a lock

Required Methods§

Source

fn lock_inner(&self) -> MutexGuard<'_, Self::Inner>

§Panics

This method will panic if the lock is poisoned

Source

fn get<S: BuildHasher>( &self, key: &K, cache: &LightCache<K, V, S, Self>, ) -> Option<V>

Source

fn insert<S: BuildHasher>( &self, key: K, value: V, cache: &LightCache<K, V, S, Self>, ) -> Option<V>

Source

fn remove<S: BuildHasher>( &self, key: &K, cache: &LightCache<K, V, S, Self>, ) -> Option<V>

Provided Methods§

Source

fn lock_and_prune<S: BuildHasher>( &self, cache: &LightCache<K, V, S, Self>, ) -> MutexGuard<'_, Self::Inner>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<K, V> Policy<K, V> for LruPolicy<K, V>
where K: Copy + Eq + Hash, V: Clone + Sync,

Source§

impl<K, V> Policy<K, V> for NoopPolicy
where K: Eq + Hash + Copy, V: Clone + Sync,

Source§

impl<K, V> Policy<K, V> for TtlPolicy<K, V>
where K: Copy + Eq + Hash, V: Clone + Sync,