pub struct CacheEntry<K, V, M = ()> {
pub key: K,
pub value: V,
pub metadata: CacheMetadata<M>,
}Expand description
Unified cache entry holding key, value, and metadata.
The M parameter allows each algorithm to store its own metadata
without affecting the core entry structure. Use () for algorithms
that don’t need extra per-entry metadata (e.g., LRU).
§Examples
use cache_rs::entry::CacheEntry;
// Create a simple entry for count-based caching
let entry: CacheEntry<&str, i32> = CacheEntry::new("key", 42, 1);
assert_eq!(entry.key, "key");
assert_eq!(entry.value, 42);
assert_eq!(entry.metadata.size, 1);Fields§
§key: KThe cached key
value: VThe cached value (or reference/handle to external storage)
metadata: CacheMetadata<M>Cache metadata including size, timestamps, and algorithm-specific data
Implementations§
Source§impl<K, V, M: Default> CacheEntry<K, V, M>
impl<K, V, M: Default> CacheEntry<K, V, M>
Sourcepub fn new(key: K, value: V, size: u64) -> Self
pub fn new(key: K, value: V, size: u64) -> Self
Creates a new cache entry without algorithm-specific metadata.
Use this constructor for algorithms like LRU that don’t need per-entry metadata beyond the basic key, value, and timestamps.
§Arguments
key- The cache keyvalue- The cached valuesize- Size of the content this entry represents (use 1 for count-based caches)
§Examples
use cache_rs::entry::CacheEntry;
// Count-based cache entry
let entry: CacheEntry<&str, String> = CacheEntry::new("user:123", "Alice".to_string(), 1);
// Size-aware cache entry
let data = vec![0u8; 1024];
let entry: CacheEntry<&str, Vec<u8>> = CacheEntry::new("file.bin", data, 1024);Source§impl<K, V, M> CacheEntry<K, V, M>
impl<K, V, M> CacheEntry<K, V, M>
Sourcepub fn with_algorithm_metadata(
key: K,
value: V,
size: u64,
algorithm_meta: M,
) -> Self
pub fn with_algorithm_metadata( key: K, value: V, size: u64, algorithm_meta: M, ) -> Self
Creates a new cache entry with algorithm-specific metadata.
Use this constructor for algorithms like LFU, LFUDA, SLRU, or GDSF that need to track additional per-entry state.
§Arguments
key- The cache keyvalue- The cached valuesize- Size of the content this entry represents (use 1 for count-based caches)algorithm_meta- Algorithm-specific metadata
§Examples
use cache_rs::entry::CacheEntry;
use cache_rs::lfu::LfuMeta;
let entry = CacheEntry::with_algorithm_metadata(
"key".to_string(),
vec![1, 2, 3],
3,
LfuMeta { frequency: 0 },
);
assert_eq!(entry.metadata.algorithm.frequency, 0);Sourcepub fn idle_nanos(&self) -> u64
pub fn idle_nanos(&self) -> u64
Gets the time since last access in nanoseconds.