Skip to main content

Crate subms_block_cache

Crate subms_block_cache 

Source
Expand description

Clock-sweep block cache. Fixed capacity. Constant-time eviction.

Slots form a ring. Each slot has a referenced bit. On insert, if the cache is full, the hand walks the ring: if the slot’s referenced bit is set, clear it; if not, evict that slot. Reads set the referenced bit on the hit slot. This is the second-chance variant of LRU - fewer per-op pointer-chasing costs, near-LRU eviction quality.

use subms_block_cache::BlockCache;
let mut c: BlockCache<u32, &'static str> = BlockCache::with_capacity(4);
c.put(1, "one");
c.put(2, "two");
assert_eq!(c.get(&1), Some(&"one"));

Structs§

BlockCache