Expand description
Pluggable eviction policy abstraction.
This module defines an EvictionStrategy enum and a
create_eviction_fn factory that returns a boxed eviction closure.
Each closure accepts a mutable Vec<(K, u64)> (a vector of (key, access_time)
pairs sorted or unsorted) and returns the key that should be evicted next.
The vector is not modified by the closure — callers are responsible for
removing the returned entry.
§Policies
| Policy | Behaviour |
|---|---|
Lru | Evict the entry with the smallest (oldest) access_time. |
Lfu | Evict the entry with the smallest access_time (access count used as proxy). |
Fifo | Evict the entry at index 0 (oldest insertion position). |
§Example
use oximedia_cache::eviction::{EvictionStrategy, create_eviction_fn};
let evict = create_eviction_fn(EvictionStrategy::Lru);
let entries: Vec<(String, u64)> = vec![
("frame-001".to_string(), 1000),
("frame-002".to_string(), 500),
("frame-003".to_string(), 2000),
];
let to_evict = evict(&entries);
assert_eq!(to_evict, Some("frame-002".to_string()));Structs§
- Eviction
Chooser - A convenience wrapper around an eviction closure.
Enums§
- Eviction
Strategy - Discriminated union of the supported eviction strategies.
Functions§
- create_
eviction_ fn - Create a boxed eviction closure for the given
policy.