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 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 { ... }
fn deep_size_of_entries(
&self,
_context: &mut Context,
_size_of_entry: &dyn Fn(&CacheEntry, &mut Context) -> Option<usize>,
) -> Option<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 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 as a DeepSizeOf fallback when exact entry traversal is unavailable.
Backends that cannot provide this cheaply should return 0.
Assumes entries do not share underlying buffers; if they do, the returned total may overcount.
Sourcefn deep_size_of_entries(
&self,
_context: &mut Context,
_size_of_entry: &dyn Fn(&CacheEntry, &mut Context) -> Option<usize>,
) -> Option<usize>
fn deep_size_of_entries( &self, _context: &mut Context, _size_of_entry: &dyn Fn(&CacheEntry, &mut Context) -> Option<usize>, ) -> Option<usize>
Computes the size of the entries currently held in memory.
size_of_entry threads a shared Context through each value so
allocations shared by multiple entries are counted once. It returns
None when the value’s concrete type was not registered by
LanceCache; implementations should use the
entry’s declared eviction size as a fallback in that case.
Backends that can enumerate their in-memory entries should include the
physical key footprint in the returned total. The default returns
None, causing LanceCache to use approx_size_bytes.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".