Expand description
Weighted cache scoring with configurable per-media-type weight factors.
Standard LRU eviction treats all entries equally. For multimedia workloads
different content types benefit from different retention policies. This
module provides WeightConfig — a table of per-type weights (recency,
size-efficiency, priority) — and WeightedCache, an LRU-ordered cache
that uses the blended score to decide which entry to evict next.
§Scoring formula
For each candidate entry the eviction score is:
score = recency_weight * recency_factor
+ priority_weight * priority_factor
- size_weight * size_factorwhere
recency_factoris1.0 - (age_ns / max_age_ns)clamped to[0, 1]priority_factoris the entry’s priority normalised to[0, 1]size_factorisentry_bytes / max_entry_bytesnormalised to[0, 1]
The entry with the lowest score is the best eviction candidate.
§Example
use oximedia_cache::weighted_cache::{WeightConfig, WeightedCache, CacheMediaType};
let weights = WeightConfig::default();
let mut cache = WeightedCache::new(256, weights);
cache.insert("seg-001", vec![0u8; 64], CacheMediaType::VideoSegment, 7);
assert!(cache.get("seg-001").is_some());Structs§
- Type
Weights - Weight factors for one media type.
- Weight
Config - Table of per-media-type weight overrides.
- Weighted
Cache - Capacity-bounded cache that uses per-media-type weight factors to choose eviction candidates.
Enums§
- Cache
Media Type - The media type label attached to a cached entry.
- Weighted
Cache Error - Errors produced by
WeightedCacheoperations.