pub struct PrefixCache { /* private fields */ }Expand description
LRU-bounded store of StoredPrefix snapshots, searched for the
longest common prefix with an incoming token sequence.
Implementations§
Source§impl PrefixCache
impl PrefixCache
pub fn new(max_entries: usize) -> Self
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drops every stored prefix, keeping the capacity and the lifetime hit/miss counters.
For a KV-side cache rebuild. A stored prefix names positions in an allocation that is about to stop existing, so handing one back afterwards would restore another request’s state into this one – silently, since a KV cache carries no identity of its own. The counters survive because they describe what this process has served, which a re-split does not undo.
Sourcepub fn find_longest_prefix(&mut self, tokens: &[usize]) -> PrefixMatch
pub fn find_longest_prefix(&mut self, tokens: &[usize]) -> PrefixMatch
Finds the stored prefix with the longest common leading
subsequence with tokens, and returns a ready-to-use clone of
its KV state truncated to exactly that common length (a stored
prefix may itself be longer than the common part, if a later,
different continuation was stored under it – the KV cache is
truncated to the matching length before being handed back, so
the caller never sees state from a divergent continuation).
Sourcepub fn store(
&mut self,
tokens: Vec<usize>,
kv_caches: Vec<KvCache>,
pending_logits: Vec<f32>,
)
pub fn store( &mut self, tokens: Vec<usize>, kv_caches: Vec<KvCache>, pending_logits: Vec<f32>, )
Stores a snapshot for tokens (all tokens processed so far,
prompt plus any generated continuation) with the given KV cache
state and next-token logits, evicting the least recently USED
entry if already at capacity.
Used, not stored. This used to drop entries[0] – the oldest
arrival – while the type documented itself as LRU-bounded. The
difference is the whole value of the cache: a system prompt that
every request shares is the oldest entry precisely BECAUSE it is
the most reused, so FIFO evicted the one entry worth keeping as
soon as max_entries newer prompts arrived, and the next
request off that system prompt recomputed all of it.
pub fn stats(&self) -> PrefixCacheStats
Auto Trait Implementations§
impl Freeze for PrefixCache
impl RefUnwindSafe for PrefixCache
impl Send for PrefixCache
impl Sync for PrefixCache
impl Unpin for PrefixCache
impl UnsafeUnpin for PrefixCache
impl UnwindSafe for PrefixCache
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
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