Struct priority_expiry_cache::PECache
source · pub struct PECache<K, V, E, P> { /* private fields */ }Implementations§
source§impl<K: Clone + Hash + Ord, V: Clone + Eq + Hash + PartialEq, E: Clone + Ord + Eq, P: Clone + Ord> PECache<K, V, E, P>
impl<K: Clone + Hash + Ord, V: Clone + Eq + Hash + PartialEq, E: Clone + Ord + Eq, P: Clone + Ord> PECache<K, V, E, P>
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, expiry: E, priority: P)
pub fn set(&mut self, key: K, value: V, expiry: E, priority: P)
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, expiry, priority) = (
String::from("key"),
String::from("value"), 1, 1);
new_cache.set(key.clone(),value.clone(), expiry, priority);
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, E, P> RefUnwindSafe for PECache<K, V, E, P>
impl<K, V, E, P> Send for PECache<K, V, E, P>
impl<K, V, E, P> Sync for PECache<K, V, E, P>
impl<K, V, E, P> Unpin for PECache<K, V, E, P>
impl<K, V, E, P> UnwindSafe for PECache<K, V, E, P>where
E: UnwindSafe + RefUnwindSafe,
K: UnwindSafe + RefUnwindSafe,
P: UnwindSafe + RefUnwindSafe,
V: 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