rust_logic_graph/cache/
policy.rs

1//! Cache eviction policies
2
3use serde::{Deserialize, Serialize};
4
5/// Strategy for evicting cache entries when limits are reached
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7pub enum EvictionPolicy {
8    /// Least Recently Used - evict entries that haven't been accessed recently
9    LRU,
10    /// First In First Out - evict oldest entries first
11    FIFO,
12    /// Least Frequently Used - evict entries with lowest access count
13    LFU,
14    /// No automatic eviction - only manual invalidation
15    None,
16}
17
18impl Default for EvictionPolicy {
19    fn default() -> Self {
20        Self::LRU
21    }
22}
23
24impl EvictionPolicy {
25    /// Get a description of the policy
26    pub fn description(&self) -> &str {
27        match self {
28            Self::LRU => "Least Recently Used - evicts entries not accessed recently",
29            Self::FIFO => "First In First Out - evicts oldest entries first",
30            Self::LFU => "Least Frequently Used - evicts entries with lowest access count",
31            Self::None => "No automatic eviction",
32        }
33    }
34}