#lru #cache #direct-mapped #associative

associative-cache

A generic N-way associative cache with fixed-size capacity and random or least recently used (LRU) replacement

2 stable releases

✓ Uses Rust 2018 edition

1.0.1 Sep 18, 2019

#23 in Caching

Download history 8/week @ 2019-12-02 69/week @ 2019-12-09 19/week @ 2019-12-16 20/week @ 2019-12-23 32/week @ 2019-12-30 187/week @ 2020-01-06 82/week @ 2020-01-13 261/week @ 2020-01-20 65/week @ 2020-01-27 111/week @ 2020-02-03 344/week @ 2020-02-10 224/week @ 2020-02-17 156/week @ 2020-02-24 239/week @ 2020-03-02 163/week @ 2020-03-09 251/week @ 2020-03-16

328 downloads per month

MIT/Apache

64KB
1K SLoC

associative_cache

A generic, fixed-size, associative cache data structure mapping K keys to V values.

Build Status

Capacity

The cache has a constant, fixed-size capacity which is controlled by the C type parameter and the Capacity trait. The memory for the cache entries is eagerly allocated once and never resized.

Associativity

The cache can be configured as direct-mapped, two-way associative, four-way associative, etc... via the I type parameter and Indices trait.

Replacement Policy

The cache can be configured to replace the least recently used (LRU) entry, or a random entry via the R type parameter and the Replacement trait.

Examples

use associative_cache::*;

// A two-way associative cache with random replacement mapping
// `String`s to `usize`s.
let cache = AssociativeCache::<
    String,
    usize,
    Capacity512,
    HashTwoWay,
    RandomReplacement
>::default();

// A four-way associative cache with random replacement mapping
// `*mut usize`s to `Vec<u8>`s.
let cache = AssociativeCache::<
    *mut usize,
    Vec<u8>,
    Capacity32,
    PointerFourWay,
    RandomReplacement
>::default();

// An eight-way associative, least recently used (LRU) cache mapping
// `std::path::PathBuf`s to `std::fs::File`s.
let cache = AssociativeCache::<
    std::path::PathBuf,
    WithLruTimestamp<std::fs::File>,
    Capacity128,
    HashEightWay,
    LruReplacement,
>::default();

Dependencies

~105KB