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_backend_and_prefix(
backend: Arc<dyn CacheBackend>,
prefix: String,
) -> Self
pub fn with_backend_and_prefix( backend: Arc<dyn CacheBackend>, prefix: String, ) -> Self
Create a cache with the given backend and an exact prefix string.
Unlike with_key_prefix, this sets the prefix verbatim (no trailing slash added).
Sourcepub fn with_key_prefix(&self, prefix: &str) -> Self
pub fn with_key_prefix(&self, prefix: &str) -> Self
Appends a prefix to the cache key.
Sourcepub async fn invalidate_prefix(&self, prefix: &str)
pub async fn invalidate_prefix(&self, prefix: &str)
Invalidate all entries whose prefix starts with the given string.
pub async fn size(&self) -> usize
pub fn approx_size(&self) -> usize
pub async fn size_bytes(&self) -> usize
Sourcepub async fn keys(&self) -> Option<CacheKeyIterator<'_>>
pub async fn keys(&self) -> Option<CacheKeyIterator<'_>>
Return an iterator over keys currently stored under this cache’s prefix.
Returns None when the backend does not support key inventory. The
iterator is intended for diagnostics and may be weakly consistent with
concurrent cache mutations.
§Examples
let cache = LanceCache::with_capacity(1024);
cache.insert_with_key(&MyKey, Arc::new(vec![1, 2, 3])).await;
let mut keys = cache.keys().await.expect("Moka supports key inventory");
assert_eq!(keys.next().unwrap().key(), "my-key");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>>
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
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LanceCache
impl Debug for LanceCache
Source§impl DeepSizeOf for LanceCache
impl DeepSizeOf for LanceCache
fn deep_size_of_children(&self, _: &mut Context) -> usize
fn deep_size_of(&self) -> usize
Auto Trait Implementations§
impl !RefUnwindSafe for LanceCache
impl !UnwindSafe for LanceCache
impl Freeze for LanceCache
impl Send for LanceCache
impl Sync for LanceCache
impl Unpin for LanceCache
impl UnsafeUnpin for LanceCache
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