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§
Required Methods§
fn key(&self) -> Cow<'_, str>
Sourcefn type_name() -> &'static str
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§
Sourcefn codec() -> Option<CacheCodec>
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.