Skip to content
/ cache Public

Type agnostic, fixed-size cache in rust

License

Notifications You must be signed in to change notification settings

JOE1994/cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
    }

About

Type agnostic, fixed-size cache in rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages