| Crates.io | fondue |
| lib.rs | fondue |
| version | 0.1.1 |
| created_at | 2023-08-05 14:24:39.960092+00 |
| updated_at | 2025-08-16 16:16:54.916029+00 |
| description | A Rust caching library with TTL, LRU, and namespace support. |
| homepage | |
| repository | https://github.com/ParkBlake/fondue |
| max_upload_size | |
| id | 936459 |
| size | 50,186 |
Fondue is a flexible and efficient caching library in Rust that supports multiple eviction policies, TTL mechanisms, cache namespaces, and usage statistics. It provides macros and APIs for easy caching of expensive computations with fine-grained control over cache behaviour.
DashMap and Arc for high concurrency and safety.Add Fondue to your Cargo.toml:
[dependencies]
fondue = "0.1"
use fondue::cache;
use fondue_core::{cache_clear_all, TtlType};
use std::thread;
use std::time::Duration;
fn expensive_calculation(x: i32) -> i32 {
thread::sleep(Duration::from_millis(100));
x * x
}
fn main() {
// Cache without TTL
let result = cache!("default", "my_key", || expensive_calculation(42));
println!("Result: {}", result);
text
// Cache with TTL of 500ms
let ttl_result = cache_with_ttl!("default", "ttl_key", "500ms", TtlType::Fixed, || {
expensive_calculation(10)
});
println!("TTL cached result: {}", ttl_result);
// Clear all caches
cache_clear_all();
}
Fondue collects cache hits, misses, entries, and hit rates which you can print or export.
None: Unlimited cache size, no eviction.Lru(limit): Least Recently Used with specified capacity.Ttl { duration, ttl_type }: Evict entries after TTL expiration; fixed or sliding.LruTtl { limit, duration, ttl_type }: Combined LRU and TTL eviction.Fondue supports human-friendly TTL strings with fractional values:
"200ms", "1.5h", "30s".Use parse_duration for manual parsing if needed.
MIT OR Apache-2.0