Skip to content

Xudong-Huang/fifo_cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fifo_cache

license

A simple rust fifo cache

If too much entries were inserted into the cache, the oldest entries would be removed from the cache to keep the cache size no bigger than the maxium size.

Examples

extern crate fifo_cache;

use std::sync::Arc;
use fifo_cache::FifoCache;

fn main() {
    let mut cache = FifoCache::<usize, usize>::new(2);
    // test empty cache
    assert_eq!(cache.get(&0), None);
    // insert entry
    assert_eq!(cache.insert(1, 1), None);
    // insert entry
    assert_eq!(cache.insert(2, 2), None);



    // this will update the entry
    assert_eq!(cache.insert(2, 4), Some(Arc::new(2)));
    // this will flush out the first entry
    assert_eq!(cache.insert(3, 3), None);
    // entry 1 is flushed out
    assert_eq!(cache.get(&1), None);
}

License

Licensed under either of

at your option.

About

rust simple fifo cache

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages