#fixed-size #values #destructor #key #arc #usizes

yanked cache

Type agnostic, fixed-size cache

Uses old Rust 2015

0.2.0 Aug 19, 2018
0.1.4 Sep 2, 2017

⚠️ Issues reported

#15 in #destructor


Used in 5 crates (via kelvin)

GPL-3.0 license

22KB
493 lines

Documentation

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
~17K SLoC