EvictingCacheMap
Backed by a HashMap but maintains order and a maximum capacity. Upon inserting beyond capacity
the cache map will remove the eldest elements to make room. Each removal or prune will call the
provided prune hook with the values.
This crate provides a no_std implementation.
Usage
fn main() {
let (tx, rx) = mpsc::channel();
let mut cachemap: EvictingCacheMap<String, u8, 10, _> =
EvictingCacheMap::with_prune_hook(move |k, v| tx.send((k, v)).unwrap());
let send = thread::spawn(move || {
for x in 0..20 {
cachemap.insert(x.to_string(), x)
}
});
let recv = thread::spawn(move || {
while let Ok((k, v)) = rx.recv() {
println!("{k}:{v}")
}
});
let _ = send.join();
let _ = recv.join();
}