pub trait CacheBackend:
Send
+ Sync
+ Debug {
// Required methods
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 InternalCacheKey,
codec: Option<CacheCodec>,
) -> Pin<Box<dyn Future<Output = Option<CacheEntry>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn insert<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 InternalCacheKey,
entry: CacheEntry,
size_bytes: usize,
codec: Option<CacheCodec>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn get_or_insert<'a, 'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 InternalCacheKey,
loader: Pin<Box<dyn Future<Output = Result<(CacheEntry, usize)>> + Send + 'a>>,
codec: Option<CacheCodec>,
) -> Pin<Box<dyn Future<Output = Result<(CacheEntry, bool)>> + Send + 'async_trait>>
where Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn invalidate_prefix<'life0, 'life1, 'async_trait>(
&'life0 self,
prefix: &'life1 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn num_entries<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn size_bytes<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn approx_num_entries(&self) -> usize { ... }
fn approx_size_bytes(&self) -> usize { ... }
}Expand description
Low-level pluggable cache backend.
Implementations store entries keyed by InternalCacheKey and return
type-erased CacheEntry values.
LanceCache handles key construction and type safety;
backend authors only need to implement storage and eviction.
Required Methods§
Sourcefn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 InternalCacheKey,
codec: Option<CacheCodec>,
) -> Pin<Box<dyn Future<Output = Option<CacheEntry>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 InternalCacheKey,
codec: Option<CacheCodec>,
) -> Pin<Box<dyn Future<Output = Option<CacheEntry>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Look up an entry by its key.
codec is provided so that persistent backends can deserialize the
entry from storage. In-memory backends can ignore it. When codec
is None, the entry type does not support serialization yet and
must be stored in-memory.
The goal is for all cache entry types to eventually have codecs,
at which point the Option will be removed.
Sourcefn insert<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 InternalCacheKey,
entry: CacheEntry,
size_bytes: usize,
codec: Option<CacheCodec>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn insert<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 InternalCacheKey,
entry: CacheEntry,
size_bytes: usize,
codec: Option<CacheCodec>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Store an entry. size_bytes is used for eviction accounting.
See get for codec semantics.
Sourcefn get_or_insert<'a, 'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 InternalCacheKey,
loader: Pin<Box<dyn Future<Output = Result<(CacheEntry, usize)>> + Send + 'a>>,
codec: Option<CacheCodec>,
) -> Pin<Box<dyn Future<Output = Result<(CacheEntry, bool)>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_or_insert<'a, 'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 InternalCacheKey,
loader: Pin<Box<dyn Future<Output = Result<(CacheEntry, usize)>> + Send + 'a>>,
codec: Option<CacheCodec>,
) -> Pin<Box<dyn Future<Output = Result<(CacheEntry, bool)>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get an existing entry or compute it from loader.
Implementations should deduplicate concurrent loads for the same key so the loader runs at most once.
Returns (entry, was_cached) where was_cached is true if the entry
was already present in the cache (the loader was not invoked).
See get for codec semantics.
Sourcefn invalidate_prefix<'life0, 'life1, 'async_trait>(
&'life0 self,
prefix: &'life1 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn invalidate_prefix<'life0, 'life1, 'async_trait>(
&'life0 self,
prefix: &'life1 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Remove all entries whose prefix starts with the given string.
Sourcefn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Remove all entries.
Provided Methods§
Sourcefn approx_num_entries(&self) -> usize
fn approx_num_entries(&self) -> usize
Approximate number of entries, callable from synchronous contexts. Backends that cannot provide this cheaply should return 0.
Sourcefn approx_size_bytes(&self) -> usize
fn approx_size_bytes(&self) -> usize
Approximate weighted size in bytes, callable from synchronous contexts.
Used by DeepSizeOf to report cache memory usage.
Backends that cannot provide this cheaply should return 0.
Assumes entries do not share underlying buffers; if they do, the returned total may overcount.