pub struct WeightedCache { /* private fields */ }Expand description
Capacity-bounded cache that uses per-media-type weight factors to choose eviction candidates.
Entries are scored on each eviction pass; the entry with the lowest score (least worth keeping) is removed first.
Implementations§
Source§impl WeightedCache
impl WeightedCache
Sourcepub fn new(capacity: usize, weights: WeightConfig) -> Self
pub fn new(capacity: usize, weights: WeightConfig) -> Self
Create a new WeightedCache with the given capacity and weight config.
§Panics
Panics if capacity is 0.
Sourcepub fn insert(
&mut self,
key: impl Into<String>,
value: Vec<u8>,
media_type: CacheMediaType,
priority: u8,
)
pub fn insert( &mut self, key: impl Into<String>, value: Vec<u8>, media_type: CacheMediaType, priority: u8, )
Insert (key, value) into the cache with the given media_type and
priority label (0–255, higher = more important).
If the key already exists it is overwritten. If the cache is at capacity, the lowest-scored entry is evicted first.
Sourcepub fn get(&mut self, key: &str) -> Option<&[u8]>
pub fn get(&mut self, key: &str) -> Option<&[u8]>
Look up key and return a reference to its value.
Records a hit or miss and updates last_accessed on hit.
Sourcepub fn remove(&mut self, key: &str) -> Option<Vec<u8>>
pub fn remove(&mut self, key: &str) -> Option<Vec<u8>>
Remove the entry for key and return it (if present).
Auto Trait Implementations§
impl Freeze for WeightedCache
impl RefUnwindSafe for WeightedCache
impl Send for WeightedCache
impl Sync for WeightedCache
impl Unpin for WeightedCache
impl UnsafeUnpin for WeightedCache
impl UnwindSafe for WeightedCache
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