pub struct ModelInvocationCache { /* private fields */ }Expand description
Memoization cache for neural classifier outputs across a single
query evaluation. Per impl plan §1.4 decision D-4: cache is scoped
per-query (cleared at the start of evaluation); the key is
(model_name, ClassifyInput::stable_hash).
Eviction policy: a naive “clear-when-full” heuristic — when the
cache reaches max_entries, the entire map is dropped. This keeps
the type allocation-light and avoids dragging in an LRU dep for
v1. Documented in impl plan as Stage 1 trade-off; a proper LRU
follow-up can swap the inner type without changing the public API.
Implementations§
Source§impl ModelInvocationCache
impl ModelInvocationCache
pub fn new(max_entries: usize) -> Self
Sourcepub fn get(&self, model: &str, input_hash: u64) -> Option<f64>
pub fn get(&self, model: &str, input_hash: u64) -> Option<f64>
Lookup. Returns Some(prob) on hit, None on miss.
Sourcepub fn insert(&self, model: &str, input_hash: u64, value: f64)
pub fn insert(&self, model: &str, input_hash: u64, value: f64)
Insert. On overflow (cache size ≥ max_entries), drops the
entire cache before inserting — naive but bounded. Callers
should size max_entries for the expected working set.
Sourcepub fn clear(&self)
pub fn clear(&self)
Empty the cache. Useful for LocyConfig users who reuse a
shared cache across evaluations and want explicit reset.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Debug for ModelInvocationCache
impl Debug for ModelInvocationCache
Source§impl Default for ModelInvocationCache
impl Default for ModelInvocationCache
Source§fn default() -> ModelInvocationCache
fn default() -> ModelInvocationCache
Auto Trait Implementations§
impl !Freeze for ModelInvocationCache
impl RefUnwindSafe for ModelInvocationCache
impl Send for ModelInvocationCache
impl Sync for ModelInvocationCache
impl Unpin for ModelInvocationCache
impl UnsafeUnpin for ModelInvocationCache
impl UnwindSafe for ModelInvocationCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more