Skip to main content

CacheWarmer

Struct CacheWarmer 

Source
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: u64

Look-ahead window: only warm entries whose predicted next access is within this many seconds of current_time.

§min_frequency: f64

Minimum accesses/hour for a key to be considered worth warming.

Implementations§

Source§

impl CacheWarmer

Source

pub fn new() -> Self

Create a new CacheWarmer with sensible defaults.

Source

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.

Source

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_efficiency

where

  • recency_weight = exp(-age_hours / 1.0) – exponential decay over 1 h
  • size_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.

Source

pub fn top_hot_keys(&self, n: usize) -> Vec<(&str, f64)>

Return the top n hot keys sorted by descending frequency.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.