9 releases

Uses old Rust 2015

0.1.2 Mar 21, 2019
0.1.1 Mar 29, 2017
0.1.0 Oct 7, 2016
0.0.7 Feb 19, 2016
0.0.2 Mar 26, 2015

#27 in Caching

Download history 297306/week @ 2024-03-14 297893/week @ 2024-03-21 308307/week @ 2024-03-28 312926/week @ 2024-04-04 309877/week @ 2024-04-11 316314/week @ 2024-04-18 303893/week @ 2024-04-25 296027/week @ 2024-05-02 293839/week @ 2024-05-09 319497/week @ 2024-05-16 317131/week @ 2024-05-23 322938/week @ 2024-05-30 320017/week @ 2024-06-06 323808/week @ 2024-06-13 321039/week @ 2024-06-20 274551/week @ 2024-06-27

1,307,088 downloads per month
Used in 1,584 crates (68 directly)

MIT/Apache

20KB
291 lines

WARNING: THIS PROJECT IS IN MAINTENANCE MODE, DUE TO INSUFFICIENT MAINTAINER RESOURCES

It works fine, but will generally no longer be improved.

We are currently only accepting changes which:

  • keep this compiling with the latest versions of Rust or its dependencies.
  • have minimal review requirements, such as documentation changes (so not totally new APIs).

A cache that holds a limited number of key-value pairs.

Documentation is available at https://contain-rs.github.io/lru-cache/lru_cache.


lib.rs:

A cache that holds a limited number of key-value pairs. When the capacity of the cache is exceeded, the least-recently-used (where "used" means a look-up or putting the pair into the cache) pair is automatically removed.

Examples

use lru_cache::LruCache;

let mut cache = LruCache::new(2);

cache.insert(1, 10);
cache.insert(2, 20);
cache.insert(3, 30);
assert!(cache.get_mut(&1).is_none());
assert_eq!(*cache.get_mut(&2).unwrap(), 20);
assert_eq!(*cache.get_mut(&3).unwrap(), 30);

cache.insert(2, 22);
assert_eq!(*cache.get_mut(&2).unwrap(), 22);

cache.insert(6, 60);
assert!(cache.get_mut(&3).is_none());

cache.set_capacity(1);
assert!(cache.get_mut(&2).is_none());

Dependencies

~220KB