Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jedisct1/rust-sieve-cache
SIEVE cache replacement policy for Rust.
https://github.com/jedisct1/rust-sieve-cache
cache caching lru policy replacement rust sieve sieve-cache
Last synced: 7 days ago
JSON representation
SIEVE cache replacement policy for Rust.
- Host: GitHub
- URL: https://github.com/jedisct1/rust-sieve-cache
- Owner: jedisct1
- License: mit
- Created: 2024-01-16T23:54:29.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2024-07-01T20:28:20.000Z (6 months ago)
- Last Synced: 2024-12-10T19:39:25.813Z (16 days ago)
- Topics: cache, caching, lru, policy, replacement, rust, sieve, sieve-cache
- Language: Rust
- Homepage:
- Size: 23.4 KB
- Stars: 16
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![dependency status](https://deps.rs/repo/github/jedisct1/rust-sieve-cache/status.svg)](https://deps.rs/repo/github/jedisct1/rust-sieve-cache)
# SIEVE cache
This is an implementation of the [SIEVE](http://sievecache.com) cache replacement algorithm for Rust.
- [API documentation](https://docs.rs/sieve-cache/0.1.2/sieve_cache)
- [`crates.io` page](https://crates.io/crates/sieve-cache)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
```rust
use sieve_cache::SieveCache;// Create a new cache with a capacity of 100000.
let mut cache: SieveCache = 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);
```