fncache
A zero-boilerplate Rust library for function-level caching with pluggable backends, inspired by functools.lru_cache and request-cache.
Features
- ð Zero Boilerplate: Simple
#[fncache]attribute for instant caching - ð Pluggable Backends: Memory, File, Redis, RocksDB support
- ⥠Async/Sync: Seamless support for both synchronous and asynchronous functions
- ðĄïļ Type Safety: Strong typing throughout the caching layer with compile-time guarantees
- ð Advanced Metrics: Built-in instrumentation with latency, hit rates, and size tracking
- ð·ïļ Cache Invalidation: Tag-based and prefix-based cache invalidation
- ðĨ Background Warming: Proactive cache population for improved performance
Quick Start
Add fncache to your Cargo.toml with the desired features:
[]
= { = "0.1", = ["memory"] }
Basic Usage
use ;
async
Async Function Example
use Duration;
use sleep;
async
Backend Examples
Redis Backend
use RedisBackend;
async
File Backend
use FileBackend;
Available Features
| Feature | Description | Default |
|---|---|---|
memory |
In-memory cache backend | â |
redis-backend |
Redis backend support | â |
file-backend |
File-based persistent cache | â |
rocksdb-backend |
RocksDB high-performance backend | â |
metrics |
Performance metrics collection | â |
invalidation |
Tag-based cache invalidation | â |
Requirements
- Rust: 1.70 or later
- Runtime:
tokiofor async support - Dependencies: Automatically managed via features
Performance
- Memory Backend: ~1-2Ξs set latency, ~850-970Ξs get hit latency
- Redis Backend: ~1ms cache hit latency (network dependent)
- File Backend: ~100Ξs cache hit latency
- Throughput: Thousands of operations/second (memory backend)
See benches/ for detailed benchmarks.
Documentation
- Architecture - Internal design and architecture
Changelog
See CHANGELOG.md for version history and breaking changes.
License
MIT License - see LICENSE for details.