Crate freqache[−][src]
Expand description
A weighted, futures-aware least-frequently-used cache.
LFUCache
by itself is not thread-safe; for thread safety you can use a tokio::sync::Mutex
.
LFUCache
does not provide a default eviction policy, but a callback and traversal method
which allow the developer to implement their own.
Example:
use freqache::LFUCache;
#[derive(Clone, Debug, Eq, PartialEq)]
struct Entry;
impl freqache::Entry for Entry {
fn weight(&self) -> u64 {
1
}
}
struct Policy;
#[async_trait]
impl freqache::Policy<String, Entry> for Policy {
fn can_evict(&self, value: &Entry) -> bool {
true
}
async fn evict(&self, key: String, value: &Entry) {
// maybe backup the entry contents here
}
}
let mut cache = LFUCache::new(1, Policy);
cache.insert("key".to_string(), Entry);
if cache.is_full() {
block_on(cache.evict());
}
Structs
A weighted, thread-safe, futures-aware least-frequently-used cache