mod moka_evictor;
pub use moka_evictor::MokaCacheEvictor;
use crate::config::CacheEvictorType;
pub trait CacheEvictor: Send + Sync {
fn on_add(&self, id: &crate::cache::page_id::PageId);
fn on_access(&self, id: &crate::cache::page_id::PageId);
fn on_remove(&self, id: &crate::cache::page_id::PageId);
fn evict_candidate(&self) -> Option<crate::cache::page_id::PageId>;
fn len(&self) -> usize;
fn is_empty(&self) -> bool {
self.len() == 0
}
}
pub fn build_evictor(policy: CacheEvictorType) -> Box<dyn CacheEvictor> {
match policy {
CacheEvictorType::Lru => Box::new(MokaCacheEvictor::new_lru()),
CacheEvictorType::Lfu => Box::new(MokaCacheEvictor::new_lfu()),
}
}