pub struct CacheMetadata<M = ()> {
pub size: u64,
pub last_accessed: u64,
pub create_time: u64,
pub algorithm: M,
}Expand description
Metadata associated with a cache entry.
This struct holds common cache metadata (size, timestamps) plus algorithm-specific
data via the M type parameter. Use () for algorithms that don’t need extra
per-entry metadata (e.g., LRU).
§Type Parameter
M: Algorithm-specific metadata type (e.g.,LfuMeta,GdsfMeta)
§Examples
use cache_rs::entry::CacheMetadata;
// Metadata without algorithm-specific data (for LRU)
let meta: CacheMetadata<()> = CacheMetadata::new(1024);
assert_eq!(meta.size, 1024);Fields§
§size: u64Size of content this entry represents (user-provided). For count-based caches, use 1. For size-aware caches, use actual bytes (memory, disk, etc.)
last_accessed: u64Last access timestamp (nanos since epoch or monotonic clock).
create_time: u64Creation timestamp (nanos since epoch or monotonic clock).
algorithm: MAlgorithm-specific metadata (frequency, priority, segment, etc.)
Implementations§
Source§impl<M: Default> CacheMetadata<M>
impl<M: Default> CacheMetadata<M>
Source§impl<M> CacheMetadata<M>
impl<M> CacheMetadata<M>
Sourcepub fn with_algorithm(size: u64, algorithm: M) -> Self
pub fn with_algorithm(size: u64, algorithm: M) -> Self
Creates new cache metadata with the specified size and algorithm metadata.
§Arguments
size- Size of the content this entry representsalgorithm- Algorithm-specific metadata
Sourcepub fn idle_nanos(&self) -> u64
pub fn idle_nanos(&self) -> u64
Gets the time since last access in nanoseconds.
Trait Implementations§
Source§impl<M: Clone> Clone for CacheMetadata<M>
impl<M: Clone> Clone for CacheMetadata<M>
Auto Trait Implementations§
impl<M> Freeze for CacheMetadata<M>where
M: Freeze,
impl<M> RefUnwindSafe for CacheMetadata<M>where
M: RefUnwindSafe,
impl<M> Send for CacheMetadata<M>where
M: Send,
impl<M> Sync for CacheMetadata<M>where
M: Sync,
impl<M> Unpin for CacheMetadata<M>where
M: Unpin,
impl<M> UnsafeUnpin for CacheMetadata<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for CacheMetadata<M>where
M: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more