Fondue
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.
Features
- Cache types: In-memory caching with optional LRU and TTL eviction policies, including sliding and fixed TTL.
- Namespace support: Isolate caches into namespaces to avoid collisions.
- Macros: Simple macros for cache access with TTL, capacity limits, and combined policies.
- Statistics: Detailed cache usage statistics with global aggregation, JSON export, and formatted output.
- Thread safe: Uses
DashMapandArcfor high concurrency and safety. - Flexible TTL parsing: Accepts human-readable TTL strings with fractional support (e.g., "500ms", "1.5h").
Getting Started
Add Fondue to your Cargo.toml:
[]
= "0.1"
Basic usage with macros
use cache;
use ;
use thread;
use Duration;
Statistics
Fondue collects cache hits, misses, entries, and hit rates which you can print or export.
Eviction Policies
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.
TTL Parsing
Fondue supports human-friendly TTL strings with fractional values:
- Examples:
"200ms","1.5h","30s". - Supported units: ns, us, ms, s, m, h, d.
Use parse_duration for manual parsing if needed.
License
MIT OR Apache-2.0