Skip to main content

StreamCache

Struct StreamCache 

Source
pub struct StreamCache {
    pub hits: u64,
    pub misses: u64,
    /* private fields */
}
Expand description

Stream-aware cache for inference pipelines.

Key insight: during inference, the filter STATE is fixed (from training). Only the DATA changes. So we cache:

  1. Filter states (from training) — keyed by config_hash + training_data_hash
  2. Chunk results — keyed by config_hash + state_hash + chunk_hash

This means: if the same chunk passes through the same filter with the same trained state, the result is returned from cache instantly.

Fields§

§hits: u64

Stats

§misses: u64

Implementations§

Source§

impl StreamCache

Source

pub fn new(max_chunks: usize) -> Self

Source

pub fn load_state(&mut self, filter_id: &str, state_key: CacheKey, state: Value)

Load a filter’s trained state into the stream cache.

Source

pub fn get_state(&self, filter_id: &str) -> Option<&Value>

Get a filter’s cached state (for forward() during inference).

Source

pub fn get_chunk(&mut self, chunk_key: &CacheKey) -> Option<&Value>

Try to get a cached chunk result. chunk_key = hash(config_hash + state_hash + chunk_data_hash)

Source

pub fn put_chunk(&mut self, chunk_key: CacheKey, value: Value)

Cache a chunk result.

Source

pub fn hit_rate(&self) -> f64

Cache hit rate.

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> Same for T

Source§

type Output = T

Should always be Self
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.