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.
Re-exports§
pub use backend::CacheBackend;pub use backend::CacheEntry;pub use backend::InternalCacheKey;pub use codec::CacheCodec;pub use codec::CacheCodecImpl;
Modules§
Structs§
- Cache
Stats - Context
- The context of which references have already been seen.
This should only be used in the implementation of the
deep_size_of_childrenfunction, and (eventually, when this reaches 0.2) will not be able to be constructed, and only obtained from inside the function. - 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.
Traits§
- Cache
Key - Typed cache key for sized value types.
- Deep
Size Of - A trait for measuring the size of an object and its children
- Unsized
Cache Key - Like
CacheKeybut for unsized value types (e.g.dyn Trait).