pub struct VectorCache { /* private fields */ }Expand description
An LRU cache for embedding vectors.
Implementations§
Source§impl VectorCache
impl VectorCache
Sourcepub fn with_config(config: VectorCacheConfig) -> Self
pub fn with_config(config: VectorCacheConfig) -> Self
Create a new cache with custom configuration.
Sourcepub fn get(&mut self, key: &str) -> Option<Vec<f64>>
pub fn get(&mut self, key: &str) -> Option<Vec<f64>>
Get a cached vector by key.
Returns None on miss. Expired entries are evicted on access.
Sourcepub fn put(&mut self, key: impl Into<String>, vector: Vec<f64>)
pub fn put(&mut self, key: impl Into<String>, vector: Vec<f64>)
Insert a vector into the cache with the default TTL.
Sourcepub fn put_with_ttl(
&mut self,
key: impl Into<String>,
vector: Vec<f64>,
ttl: Option<Duration>,
)
pub fn put_with_ttl( &mut self, key: impl Into<String>, vector: Vec<f64>, ttl: Option<Duration>, )
Insert a vector with an explicit per-entry TTL.
Sourcepub fn batch_get(&mut self, keys: &[&str]) -> HashMap<String, Vec<f64>>
pub fn batch_get(&mut self, keys: &[&str]) -> HashMap<String, Vec<f64>>
Batch get: returns a map of key → vector for found entries.
Sourcepub fn batch_put(&mut self, entries: Vec<(String, Vec<f64>)>)
pub fn batch_put(&mut self, entries: Vec<(String, Vec<f64>)>)
Batch put: insert multiple entries at once.
Sourcepub fn warm(&mut self, entries: Vec<(String, Vec<f64>)>) -> usize
pub fn warm(&mut self, entries: Vec<(String, Vec<f64>)>) -> usize
Warm the cache by preloading the given key-vector pairs.
Existing entries are not overwritten.
Sourcepub fn invalidate(&mut self, key: &str) -> bool
pub fn invalidate(&mut self, key: &str) -> bool
Remove a specific key from the cache.
Sourcepub fn invalidate_prefix(&mut self, prefix: &str) -> usize
pub fn invalidate_prefix(&mut self, prefix: &str) -> usize
Remove all keys matching a given prefix.
Sourcepub fn statistics(&self) -> &CacheStatistics
pub fn statistics(&self) -> &CacheStatistics
Current cache statistics.
Sourcepub fn reset_statistics(&mut self)
pub fn reset_statistics(&mut self)
Reset statistics counters to zero.
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Approximate total memory usage in bytes.
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Check if a key exists in the cache (without affecting LRU order).
Sourcepub fn snapshot(&self) -> CacheSnapshot
pub fn snapshot(&self) -> CacheSnapshot
Create a snapshot of the current cache contents.
Sourcepub fn load_snapshot(&mut self, snapshot: CacheSnapshot) -> usize
pub fn load_snapshot(&mut self, snapshot: CacheSnapshot) -> usize
Load entries from a snapshot (appending to the current cache).
Sourcepub fn sweep_expired(&mut self) -> usize
pub fn sweep_expired(&mut self) -> usize
Sweep expired entries from the cache.
Returns the number of entries removed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for VectorCache
impl RefUnwindSafe for VectorCache
impl Send for VectorCache
impl Sync for VectorCache
impl Unpin for VectorCache
impl UnsafeUnpin for VectorCache
impl UnwindSafe for VectorCache
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.