lru

An implementation of a LRU cache

Latest version: 0.16.3 registry icon
Maintenance score
58
Safety score
94
Popularity score
84
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
0.16.3 0 0 0 0 0
0.16.2 0 0 1 0 0
0.16.1 0 0 1 0 0
0.16.0 0 0 1 0 0
0.15.0 0 0 1 0 0
0.14.0 0 0 1 0 0
0.13.0 0 0 1 0 0
0.12.5 0 0 1 0 0
0.12.4 0 0 1 0 0
0.12.3 0 0 1 0 0
0.12.2 0 0 1 0 0
0.12.1 0 0 1 0 0
0.12.0 0 0 1 0 0
0.11.1 0 0 1 0 0
0.11.0 0 0 1 0 0
0.10.1 0 0 1 0 0
0.10.0 0 0 1 0 0
0.9.0 0 0 1 0 0
0.8.1 0 0 0 0 0
0.8.0 0 0 0 0 0
0.7.8 0 0 0 0 0
0.7.7 0 0 0 0 0
0.7.6 0 0 0 0 0
0.7.5 0 0 0 0 0
0.7.4 0 0 0 0 0
0.7.3 0 0 0 0 0
0.7.2 0 0 0 0 0
0.7.1 0 0 0 0 0
0.7.0 0 0 1 0 0
0.6.6 0 0 1 0 0
0.6.5 0 0 1 0 0
0.6.4 0 0 1 0 0
0.6.3 0 0 1 0 0
0.6.2 0 0 1 0 0
0.6.1 0 0 1 0 0
0.6.0 0 0 1 0 0
0.5.3 0 0 1 0 0
0.5.2 0 0 1 0 0
0.5.1 0 0 1 0 0
0.5.0 0 0 1 0 0
0.4.5 0 0 1 0 0
0.4.4 0 0 1 0 0
0.4.3 0 0 1 0 0
0.4.2 0 0 1 0 0
0.4.1 0 0 1 0 0
0.4.0 0 0 1 0 0
0.3.1 0 0 1 0 0
0.3.0 0 0 1 0 0
0.2.0 0 0 1 0 0
0.1.18 0 0 1 0 0
0.1.17 0 0 1 0 0
0.1.16 0 0 1 0 0
0.1.15 0 0 1 0 0
0.1.14 0 0 1 0 0
0.1.13 0 0 1 0 0
0.1.12 0 0 1 0 0
0.1.11 0 0 1 0 0
0.1.10 0 0 1 0 0
0.1.9 0 0 1 0 0
0.1.8 0 0 1 0 0
0.1.7 0 0 1 0 0
0.1.6 0 0 1 0 0
0.1.5 0 0 1 0 0
0.1.4 0 0 1 0 0
0.1.3 0 0 1 0 0
0.1.2 0 0 1 0 0
0.1.1 0 0 1 0 0
0.1.0 0 0 1 0 0

Stability
Latest release:

0.16.3 - This version is safe to use because it has no known security vulnerabilities at this time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



LRU Cache

Build Badge crates.io Badge docs.rs Badge License Badge

Documentation

An implementation of a LRU cache. The cache supports put, get, get_mut and pop operations, all of which are O(1). This crate was heavily influenced by the LRU Cache implementation in an earlier version of Rust's std::collections crate.

The MSRV for this crate is 1.70.0.

Example

Below is a simple example of how to instantiate and use a LRU cache.

extern crate lru;

use lru::LruCache;
use std::num::NonZeroUsize;

fn main() {
    let mut cache = LruCache::new(NonZeroUsize::new(2).unwrap());
    cache.put("apple", 3);
    cache.put("banana", 2);

    assert_eq!(*cache.get(&"apple").unwrap(), 3);
    assert_eq!(*cache.get(&"banana").unwrap(), 2);
    assert!(cache.get(&"pear").is_none());

    assert_eq!(cache.put("banana", 4), Some(2));
    assert_eq!(cache.put("pear", 5), None);

    assert_eq!(*cache.get(&"pear").unwrap(), 5);
    assert_eq!(*cache.get(&"banana").unwrap(), 4);
    assert!(cache.get(&"apple").is_none());

    {
        let v = cache.get_mut(&"banana").unwrap();
        *v = 6;
    }

    assert_eq!(*cache.get(&"banana").unwrap(), 6);
}