evicting_cache_map 0.6.0

An Evicting LRU cache supporting prune hooks
Documentation
//! Example of having a cleanup thread.
//!
//! In some instances objects may be expensive to delete. Sending objects to a dedicated cleanup
//! thread can alleviate the load on the workers.
//!
//! The sender thread writes key/value pairs from 0 through 19 with a max cachemap size of 10. This
//! will result in elements 0 through 9 being pushed out and sent on the channel where they are
//! written to stdout.

use evicting_cache_map::EvictingCacheMap;
use ordered_hash_map as _;
use std::sync::mpsc;
use std::thread;

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 _unused = send.join();
    let _unused = recv.join();
}