pub struct LanceCache { /* private fields */ }Expand description
Typed cache wrapper that handles key construction and type safety.
Internally delegates to a CacheBackend. The default backend is
MokaCacheBackend; pass a custom backend via LanceCache::with_backend.
Implementations§
Source§impl LanceCache
impl LanceCache
pub fn with_capacity(capacity: usize) -> Self
Sourcepub fn with_backend(backend: Arc<dyn CacheBackend>) -> Self
pub fn with_backend(backend: Arc<dyn CacheBackend>) -> Self
Create a cache backed by a custom CacheBackend.
pub fn no_cache() -> Self
Sourcepub fn with_key_prefix(&self, prefix: &str) -> Self
pub fn with_key_prefix(&self, prefix: &str) -> Self
Derive a child namespace for all keys in the returned cache handle.
Each call adds one framed hierarchy segment. Consequently,
cache.with_key_prefix("a").with_key_prefix("b") is deliberately
distinct from cache.with_key_prefix("a/b").
pub async fn size(&self) -> usize
pub fn approx_size(&self) -> usize
pub async fn size_bytes(&self) -> usize
pub async fn stats(&self) -> CacheStats
pub async fn clear(&self)
pub async fn insert_with_key<K>( &self, cache_key: &K, metadata: Arc<K::ValueType>, )
pub async fn get_with_key<K>(&self, cache_key: &K) -> Option<Arc<K::ValueType>>
pub async fn get_or_insert_with_key<K, F, Fut>( &self, cache_key: K, loader: F, ) -> Result<Arc<K::ValueType>>
Sourcepub async fn get_or_insert_with_key_hit<K, F, Fut>(
&self,
cache_key: K,
loader: F,
) -> Result<(Arc<K::ValueType>, bool)>
pub async fn get_or_insert_with_key_hit<K, F, Fut>( &self, cache_key: K, loader: F, ) -> Result<(Arc<K::ValueType>, bool)>
Same as get_or_insert_with_key, but
also returns a boolean indicating whether the loader was skipped for
this call.
truemeans this call did not execute the loader. That covers both a true cache hit on an already-populated entry and a coalesced concurrent load where an in-flight loader started by a different caller produced the value.falsemeans the loader ran on this call (a real cache miss).
Callers that want strict “served from cache” semantics should treat
coalesced loads as misses; the current backend does not distinguish the
two cases. Prefer this over rolling a caller-side Arc<AtomicBool>
when the caller needs per-query hit/miss counters — the backend already
tracks this bit internally and this method just exposes it.
pub async fn insert_unsized_with_key<K>( &self, cache_key: &K, metadata: Arc<K::ValueType>, )
pub async fn get_unsized_with_key<K>( &self, cache_key: &K, ) -> Option<Arc<K::ValueType>>
Trait Implementations§
Source§impl Clone for LanceCache
impl Clone for LanceCache
Source§fn clone(&self) -> LanceCache
fn clone(&self) -> LanceCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more