pub struct PECache<K, V, P, E> { /* private fields */ }Implementations§
Source§impl<K: Clone + Hash + Ord, V: Clone + Eq + Hash + PartialEq, P: Clone + Ord, E: Clone + Ord + Eq> PECache<K, V, P, E>
impl<K: Clone + Hash + Ord, V: Clone + Eq + Hash + PartialEq, P: Clone + Ord, E: Clone + Ord + Eq> PECache<K, V, P, E>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new PE Cache.
§Examples
use priority_expiry_cache::PECache;
let mut new_cache:PECache<String,String,u32,u32>= PECache::new();Sourcepub fn set(&mut self, key: K, value: V, priority: P, expiry: E)
pub fn set(&mut self, key: K, value: V, priority: P, expiry: E)
Add a new item to the cache or override the existing one if present in O(1) time.
§Examples
use priority_expiry_cache::PECache;
let mut new_cache:PECache<String,String,u32,u32>= PECache::new();
let (key, value, priority, expiry) = (
String::from("key"),
String::from("value"), 1, 1);
new_cache.set(key.clone(),value.clone(), priority, expiry);
Sourcepub fn get(&mut self, key: K) -> Option<V>
pub fn get(&mut self, key: K) -> Option<V>
Gat the value associated with the key if present or None if not in O(1) time.
§Examples
use priority_expiry_cache::PECache;
let mut new_cache:PECache<String,String,u32,u32>= PECache::new();
// the get operation
let extracted_value = new_cache.get("key".to_string());Sourcepub fn evict(&mut self, barrier: E)
pub fn evict(&mut self, barrier: E)
Evict 1 element following this policy if at least one element is present in O(1).
Policy:
- If an expired item is available. Remove it. If multiple items have the same expiry, removing any one suffices.
- If condition #1 can’t be satisfied, remove an item with the least priority.
- If more than one item satisfies condition #2, remove the least recently used one.
- Multiple items can have the same priority and expiry.
§Examples
use priority_expiry_cache::PECache;
let mut new_cache:PECache<String,String,u32,u32>= PECache::new();
let extracted_value = new_cache.evict(10);Auto Trait Implementations§
impl<K, V, P, E> Freeze for PECache<K, V, P, E>
impl<K, V, P, E> RefUnwindSafe for PECache<K, V, P, E>
impl<K, V, P, E> Send for PECache<K, V, P, E>
impl<K, V, P, E> Sync for PECache<K, V, P, E>
impl<K, V, P, E> Unpin for PECache<K, V, P, E>
impl<K, V, P, E> UnwindSafe for PECache<K, V, P, E>where
K: UnwindSafe + RefUnwindSafe,
P: RefUnwindSafe + UnwindSafe,
V: UnwindSafe,
E: UnwindSafe + RefUnwindSafe,
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