Skip to main content

CacheKey

Trait CacheKey 

Source
pub trait CacheKey {
    type ValueType: 'static;

    // Required methods
    fn key(&self) -> Cow<'_, str>;
    fn type_name() -> &'static str;

    // Provided method
    fn codec() -> Option<CacheCodec> { ... }
}
Expand description

Typed cache key for sized value types.

Implement this trait to define a new type of cached entry. LanceCache uses the key string and type name to construct an InternalCacheKey for the backend.

§Example

struct MyKey { id: u64 }

impl CacheKey for MyKey {
    type ValueType = MyData;
    fn key(&self) -> Cow<'_, str> { self.id.to_string().into() }
    fn type_name() -> &'static str { "MyData" }
}

Required Associated Types§

Source

type ValueType: 'static

Required Methods§

Source

fn key(&self) -> Cow<'_, str>

Source

fn type_name() -> &'static str

Short, stable string identifying this value type.

Two CacheKey impls that store different ValueTypes must return different type names; if they collide, gets will silently return None due to failed downcasts.

Use a short literal (e.g. "Vec<IndexMetadata>"), not std::any::type_name — the latter is not guaranteed stable across compiler versions or build configurations.

Provided Methods§

Source

fn codec() -> Option<CacheCodec>

Optional codec for serializing/deserializing this key’s value type.

Returns None by default. Cache backends that support persistence (e.g. disk-backed caches) use this to serialize entries on insert and deserialize on get. Types without a codec will only be stored in-memory.

CacheCodec is Copy (two plain function pointers), so returning it by value is cheap — no allocation needed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§