use std::hash::BuildHasher;
use std::sync::MutexGuard;
use crate::LightCache;
pub mod lru;
pub mod noop;
pub mod ttl;
mod linked_arena;
pub use noop::NoopPolicy;
pub use ttl::TtlPolicy;
pub trait Policy<K, V>: Sized {
type Inner: Prune<K, V, Self>;
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>;
fn lock_and_prune<S: BuildHasher>(&self, cache: &LightCache<K, V, S, Self>) -> MutexGuard<'_, Self::Inner> {
let mut lock = self.lock_inner();
lock.prune(cache);
lock
}
}
pub trait Prune<K, V, P> {
fn prune<S: BuildHasher>(&mut self, cache: &LightCache<K, V, S, P>);
}