#cache

cache

Type agnostic, fixed-size cache

6 releases

0.2.0 Aug 19, 2018
0.1.4 Sep 2, 2017

#76 in Caching

Download history 14/week @ 2019-11-28 14/week @ 2019-12-05 33/week @ 2019-12-12 3/week @ 2019-12-19 9/week @ 2019-12-26 1/week @ 2020-01-02 26/week @ 2020-01-09 28/week @ 2020-01-16 1/week @ 2020-01-23 14/week @ 2020-01-30 7/week @ 2020-02-06 17/week @ 2020-02-13 21/week @ 2020-02-20 47/week @ 2020-02-27 15/week @ 2020-03-05 8/week @ 2020-03-12

59 downloads per month
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
~16K SLoC