pub struct Cache { /* private fields */ }Expand description
On-disk content-addressed embedding cache.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open or create a cache at path with no TTL.
Sourcepub fn open_with_ttl<P: AsRef<Path>>(
path: P,
ttl_secs: Option<u64>,
) -> Result<Self>
pub fn open_with_ttl<P: AsRef<Path>>( path: P, ttl_secs: Option<u64>, ) -> Result<Self>
Open or create a cache at path with an optional TTL in seconds.
Sourcepub fn key(model: &str, text: &str) -> [u8; 32]
pub fn key(model: &str, text: &str) -> [u8; 32]
32-byte content-addressed key for (model, text).
Sourcepub fn get(&self, model: &str, text: &str) -> Result<Option<Vec<f32>>>
pub fn get(&self, model: &str, text: &str) -> Result<Option<Vec<f32>>>
Look up a vector. Returns None if absent or expired.
Sourcepub fn put(&self, model: &str, text: &str, vector: &[f32]) -> Result<()>
pub fn put(&self, model: &str, text: &str, vector: &[f32]) -> Result<()>
Insert or overwrite a vector for (model, text).
Sourcepub fn remove(&self, model: &str, text: &str) -> Result<bool>
pub fn remove(&self, model: &str, text: &str) -> Result<bool>
Remove a single entry. Returns true if the key was present.
Sourcepub fn purge_expired(&self) -> Result<u64>
pub fn purge_expired(&self) -> Result<u64>
Remove every entry whose inserted_at + ttl < now. Returns the count.
No-op when the cache has no TTL.
Sourcepub fn purge_to_size(&self, target_bytes: u64) -> Result<u64>
pub fn purge_to_size(&self, target_bytes: u64) -> Result<u64>
Evict oldest entries until the total stored value bytes are
<= target_bytes. Returns the count removed.
Sourcepub fn stats(&self) -> Result<CacheStats>
pub fn stats(&self) -> Result<CacheStats>
Counts and bytes for the cache.
Auto Trait Implementations§
impl Freeze for Cache
impl !RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnsafeUnpin for Cache
impl !UnwindSafe for Cache
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
Mutably borrows from an owned value. Read more