Uses old Rust 2015
0.2.0 |
|
---|---|
0.1.4 |
|
#13 in #caching
Used in 5 crates
(via kelvin)
22KB
493 lines
Cache
Fixed-size LRU-Cache capable of caching values of different type.
Example
Example demonstrating caching two different types in the cache, and having destructors run.
#[test]
fn destructors() {
let cache = Cache::new(1, 4096);
let arc = Arc::new(42usize);
cache.insert(0, arc.clone());
assert_eq!(Arc::strong_count(&arc), 2);
let n: usize = 10_000;
// spam usizes to make arc fall out
for i in 1..n {
cache.insert(i, i);
}
// arc should have fallen out
assert!(cache.get::<Arc<usize>>(&0).is_none());
// and had its destructor run
assert_eq!(Arc::strong_count(&arc), 1);
}
lib.rs
:
In-memory fixed-size cache for arbitrary types.
Primarily intended for content-addressable storage, where the key uniquely identifies a value.
Dependencies
~1MB
~18K SLoC