#key-value #cache #pair #lru-cache #numbers #hold #limited

xlru-cache

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

1 unstable release

Uses old Rust 2015

0.1.2 Nov 24, 2019

#3 in #holds

Download history 89/week @ 2024-03-13 67/week @ 2024-03-20 71/week @ 2024-03-27 81/week @ 2024-04-03 176/week @ 2024-04-10 107/week @ 2024-04-17 87/week @ 2024-04-24 67/week @ 2024-05-01 43/week @ 2024-05-08 83/week @ 2024-05-15 86/week @ 2024-05-22 87/week @ 2024-05-29 214/week @ 2024-06-05 173/week @ 2024-06-12 93/week @ 2024-06-19 60/week @ 2024-06-26

556 downloads per month
Used in arc-cache

MIT/Apache

20KB
284 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