Skip to main content

Module eviction

Module eviction 

Source
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

PolicyBehaviour
LruEvict the entry with the smallest (oldest) access_time.
LfuEvict the entry with the smallest access_time (access count used as proxy).
FifoEvict 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§

EvictionChooser
A convenience wrapper around an eviction closure.

Enums§

EvictionStrategy
Discriminated union of the supported eviction strategies.

Functions§

create_eviction_fn
Create a boxed eviction closure for the given policy.