tiered-cache-0.1.1 has been yanked.
tiered-cache
A high-performance multi-tiered cache implementation in Rust with automatic sizing and async support.
Features
- 🚀 Multiple cache tiers with automatic item placement based on size
- ⚡ Async support with Tokio
- 🔄 Built-in TTL support
- 📊 Detailed statistics for monitoring
- 🔍 Efficient lookup with DashMap
- 🛡️ Thread-safe design
- 📦 Zero unsafe code
Installation
Add this to your Cargo.toml:
[]
= "0.1.1"
Quick Start
use ;
use Duration;
const MB: usize = 1024 * 1024;
// Configure a cache with two tiers
let config = CacheConfig ;
// Create the cache
let cache = new;
// Basic operations
cache.put;
if let Some = cache.get
// Async get_or_update
let value = cache.get_or_update.await;
Cache Configuration
The cache is configured using tiers, where each tier has:
- A total capacity in bytes
- A size range for entries (min_size, max_size)
- Optional TTL for entries
Items are automatically placed in the appropriate tier based on their size. The cache uses the HeapSize trait to accurately measure memory usage.
Performance
The implementation uses:
DashMapfor concurrent key-to-tier mappingparking_lotlocks for low contentionSmallVecfor efficient tier storage- Cache-padded structures to prevent false sharing
Examples
See the examples directory for more usage examples, including:
- Setting up a 1GB cache with multiple tiers
- Handling different value sizes
- Monitoring cache statistics
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.