A minimalist, thread-safe, FIFO (First In, First Out) cache with TTL (Time To Live) support for Rust.
- FIFO eviction policy: Oldest entries are removed when capacity is reached
- TTL support: Entries automatically expire after a specified duration
- Zero dependencies: Uses only standard library types
- Thread-safe: Can be wrapped in
Arc<RwLock<>>(orArc<Mutex<>>) for concurrent access - TTL and capacity can be modified after cache creation
Add this to your Cargo.toml:
[dependencies]
fifo-cache = "0.2"Or, for no TTL:
[dependencies]
fifo-cache = { version = "0.2", default-features = false }use fifo_cache::FifoCache;
use std::time::Duration;
let mut cache = FifoCache::new(1000, Duration::from_secs(300));
cache.insert("key", "value");
if let Some(value) = cache.get(&"key") {
println!("Found: {}", value);
}To run the tests, use the following command:
cargo testThe minimum required Rust version is 1.59. While this is unlikely to change in the foreseeable future, the main objective is to remain at or below Rust 1.77, so as to preserve Windows 7 compatibility.
To test with Rust 1.77:
- Change
version = 4toversion = 3inCargo.lock. - Install the 1.77 target:
rustup install 1.77.0-x86_64-pc-windows-gnu. - Then run clippy and the tests as follows:
cargo +1.77 clippy
cargo +1.77 test
cargo run --example basic_usage