Skip to main content

CacheKey

Trait CacheKey 

Source
pub trait CacheKey:
    Hash
    + Eq
    + Clone
    + Send
    + Sync
    + 'static {
    type Value: DeepSizeOf + Send + Sync;

    // Provided method
    fn policy(&self) -> CachePolicy { ... }
}
Expand description

Marker trait for cache keys. Associates a key type with its value type.

§Example

use priority_lfu::{DeepSizeOf, CacheKey, CachePolicy};

#[derive(Hash, Eq, PartialEq, Clone)]
struct UserId(u64);

#[derive(Clone, Debug, PartialEq, DeepSizeOf)]
struct UserData {
    name: String,
}

impl CacheKey for UserId {
    type Value = UserData;

    fn policy(&self) -> CachePolicy {
        CachePolicy::Standard
    }
}

Required Associated Types§

Source

type Value: DeepSizeOf + Send + Sync

The value type associated with this key.

Provided Methods§

Source

fn policy(&self) -> CachePolicy

Eviction policy determining retention priority.

This method is called on the key, allowing different keys to have different policies for the same value type.

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§