Skip to main content

Cache

Struct Cache 

Source
pub struct Cache { /* private fields */ }
Expand description

On-disk content-addressed embedding cache.

Implementations§

Source§

impl Cache

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open or create a cache at path with no TTL.

Source

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.

Source

pub fn key(model: &str, text: &str) -> [u8; 32]

32-byte content-addressed key for (model, text).

Source

pub fn get(&self, model: &str, text: &str) -> Result<Option<Vec<f32>>>

Look up a vector. Returns None if absent or expired.

Source

pub fn put(&self, model: &str, text: &str, vector: &[f32]) -> Result<()>

Insert or overwrite a vector for (model, text).

Source

pub fn remove(&self, model: &str, text: &str) -> Result<bool>

Remove a single entry. Returns true if the key was present.

Source

pub fn clear(&self) -> Result<u64>

Remove every entry. Returns the number of entries removed.

Source

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.

Source

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.

Source

pub fn stats(&self) -> Result<CacheStats>

Counts and bytes for the cache.

Source

pub fn len(&self) -> Result<u64>

Number of entries.

Source

pub fn is_empty(&self) -> Result<bool>

True if no entries are stored.

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> 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, 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.