7 releases

0.2.1 Jul 1, 2024
0.2.0 May 16, 2024
0.1.4 Jan 17, 2024

#39 in Caching

Download history 708/week @ 2024-07-08 1302/week @ 2024-07-15 1475/week @ 2024-07-22 789/week @ 2024-07-29 770/week @ 2024-08-05 641/week @ 2024-08-12 628/week @ 2024-08-19 1084/week @ 2024-08-26 953/week @ 2024-09-02 1560/week @ 2024-09-09 1546/week @ 2024-09-16 801/week @ 2024-09-23 1177/week @ 2024-09-30 775/week @ 2024-10-07 625/week @ 2024-10-14 120/week @ 2024-10-21

2,852 downloads per month
Used in encrypted-dns

MIT license

11KB
193 lines

dependency status

SIEVE cache

This is an implementation of the SIEVE cache replacement algorithm for Rust.

SIEVE is an eviction algorithm simpler than LRU that achieves state-of-the-art efficiency on skewed workloads.

This implementation exposes the same API as the clock-pro and arc-cache crates, so it can be used as a drop-in replacement for them in existing applications.

Usage example

use sieve_cache::SieveCache;

// Create a new cache with a capacity of 100000.
let mut cache: SieveCache<String, String> = SieveCache::new(100000).unwrap();

// Insert key/value pairs into the cache.
cache.insert("foo".to_string(), "foocontent".to_string());
cache.insert("bar".to_string(), "barcontent".to_string());

// Remove an entry from the cache.
cache.remove("bar");

// Retrieve a value from the cache, returning `None` or a reference to the value.
assert_eq!(cache.get("foo"), Some(&"foocontent".to_string()));

// Check if a key is in the cache.
assert_eq!(cache.contains_key("bar"), false);

// Get a mutable reference to a value in the cache.
if let Some(value) = cache.get_mut("foo") {
   *value = "newfoocontent".to_string();
}

// Return the number of cached values.
assert_eq!(cache.len(), 1);

// Return the capacity of the cache.
assert_eq!(cache.capacity(), 100000);

No runtime deps