pub struct CacheEntry {
pub key: String,
pub data: Vec<u8>,
pub content_type: MediaContentType,
pub inserted_at: Instant,
pub last_accessed: Instant,
pub access_count: u32,
pub size_bytes: usize,
}Expand description
A single entry held in ContentAwareCache.
Fields§
§key: StringThe cache key.
data: Vec<u8>Raw payload bytes.
content_type: MediaContentTypeMedia content type (determines priority and TTL).
inserted_at: InstantWall-clock time at which this entry was first inserted.
last_accessed: InstantWall-clock time of the most recent successful lookup.
access_count: u32Total number of successful lookups since insertion.
size_bytes: usizedata.len() cached to avoid recomputation.
Implementations§
Source§impl CacheEntry
impl CacheEntry
Sourcepub fn score_for_eviction(&self) -> f32
pub fn score_for_eviction(&self) -> f32
Compute the eviction score for this entry using default weights.
A higher score means the entry is a better eviction candidate (i.e. it should be evicted first).
score = (1.0 - recency) × (1.0 / priority) × size_factorWhere:
recency = e^(-age_secs / 60.0)— exponential decay over 1 minute.priority = ContentCachePriority::for_type(content_type).0cast to f32.size_factor = size_bytes / 1_048_576.0 + 1.0— larger entries score higher (give bigger bang for the eviction buck).
Sourcepub fn score_for_eviction_weighted(&self, w: &ScoringWeights) -> f32
pub fn score_for_eviction_weighted(&self, w: &ScoringWeights) -> f32
Compute the eviction score using configurable ScoringWeights.
score = (1 - recency).powf(w.recency_exp)
× (1 / priority).powf(w.priority_exp)
× size_factor.powf(w.size_exp)Default weights (recency_exp = priority_exp = size_exp = 1.0)
reproduce the original behaviour exactly.
Trait Implementations§
Source§impl Clone for CacheEntry
impl Clone for CacheEntry
Source§fn clone(&self) -> CacheEntry
fn clone(&self) -> CacheEntry
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CacheEntry
impl RefUnwindSafe for CacheEntry
impl Send for CacheEntry
impl Sync for CacheEntry
impl Unpin for CacheEntry
impl UnsafeUnpin for CacheEntry
impl UnwindSafe for CacheEntry
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