Expand description
Lance cache system.
§For cache users
Use LanceCache (or WeakLanceCache) to store and retrieve typed
values. Define a CacheKey (or UnsizedCacheKey for trait objects) to
describe what you’re caching and its type.
To make a value type serializable (so persistent backends can store it),
implement CacheCodecImpl on the type, then override CacheKey::codec:
ⓘ
impl CacheCodecImpl for MyData {
fn serialize(&self, w: &mut dyn Write) -> Result<()> { /* ... */ }
fn deserialize(data: &Bytes) -> Result<Self> { /* ... */ }
}
impl CacheKey for MyDataKey {
type ValueType = MyData;
fn key(&self) -> Cow<'_, str> { /* ... */ }
fn type_name() -> &'static str { "MyData" }
fn codec() -> Option<CacheCodec> {
Some(CacheCodec::from_impl::<MyData>())
}
}§For backend implementors
Implement CacheBackend to provide a custom storage layer (disk, Redis,
etc.). Backends receive InternalCacheKey keys and type-erased
CacheEntry values — the typed wrapping is handled by LanceCache.
See the backend module for details.
§Serialization flow
When a CacheKey provides a codec via CacheKey::codec:
LanceCachewraps theCacheCodecand passes it to the backend alongside the entry oninsertandgetcalls.- In-memory backends (like
MokaCacheBackend) ignore the codec. - Persistent backends use
codec.serialize(entry, writer)on insert andcodec.deserialize(reader)on get to persist entries across restarts.
Modules§
Structs§
- Cache
Codec - Type-erased codec for serializing and deserializing cache entries.
- Cache
Entry Reader - Reads a cache entry body, tracking an offset into the input and exposing
the entry’s
type_versionso implementors can branch for backward compat. - Cache
Entry Writer - Writes a cache entry body: a header followed by sections, streaming directly to the underlying writer.
- Cache
Stats - Context
- Internal
Cache Key - Structured cache key passed to
CacheBackendmethods. - Lance
Cache - Typed cache wrapper that handles key construction and type safety.
- Moka
Cache Backend - Default
CacheBackendbacked by a moka cache. - Weak
Lance Cache - A weak reference to a LanceCache, used by indices to avoid circular references. When the original cache is dropped, operations on this will gracefully no-op.
Enums§
- Cache
Decode - Outcome of deserializing a cache entry.
- Cache
Miss Reason - Why a cache entry could not be decoded into the expected type.
Constants§
- MAGIC
- Magic bytes that prefix every stabilized cache entry.
Traits§
- Cache
Backend - Low-level pluggable cache backend.
- Cache
Codec Impl - Serialization trait for cache entries.
- Cache
Key - Typed cache key for sized value types.
- Deep
Size Of - Unsized
Cache Key - Like
CacheKeybut for unsized value types (e.g.dyn Trait).
Functions§
- has_
cache_ envelope - Returns
trueifdatabegins with the cache-entryMAGIC.
Type Aliases§
- Cache
Entry - A type-erased cache entry.
- Cache
KeyIterator - Iterator over cache keys currently known to a backend.
Derive Macros§
- Deep
Size Of - Derive macro for the
DeepSizeOftrait.