pub struct CacheWarmer {
pub patterns: Vec<AccessPattern>,
pub look_ahead_secs: u64,
pub min_frequency: f64,
}Expand description
Predictive cache warmer.
Fields§
§patterns: Vec<AccessPattern>All recorded access patterns, keyed by cache key.
look_ahead_secs: u64Look-ahead window: only warm entries whose predicted next access is
within this many seconds of current_time.
min_frequency: f64Minimum accesses/hour for a key to be considered worth warming.
Implementations§
Source§impl CacheWarmer
impl CacheWarmer
Sourcepub fn record_access(&mut self, key: &str, size_bytes: usize, time: u64)
pub fn record_access(&mut self, key: &str, size_bytes: usize, time: u64)
Record an access to key at time (Unix seconds).
If no pattern for this key exists yet, one is created.
Sourcepub fn plan_warmup(
&self,
current_time: u64,
available_bytes: usize,
) -> WarmupPlan
pub fn plan_warmup( &self, current_time: u64, available_bytes: usize, ) -> WarmupPlan
Build a WarmupPlan prioritising entries by:
score = frequency_per_hour × recency_weight × size_efficiencywhere
recency_weight = exp(-age_hours / 1.0)– exponential decay over 1 hsize_efficiency = 1.0 / (1.0 + size_bytes / 1024)
Only entries whose predicted next access is within look_ahead_secs
of current_time and whose frequency exceeds min_frequency are
considered. Entries are added in descending score order until
available_bytes would be exceeded.
Auto Trait Implementations§
impl Freeze for CacheWarmer
impl RefUnwindSafe for CacheWarmer
impl Send for CacheWarmer
impl Sync for CacheWarmer
impl Unpin for CacheWarmer
impl UnsafeUnpin for CacheWarmer
impl UnwindSafe for CacheWarmer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more