🪟 W-TinyLFU (Windowed Tiny LFU) Policy!
Version 0.16.0 introduces the W-TinyLFU eviction policy, a state-of-the-art cache replacement algorithm that delivers excellent hit rates:
Key Features:
-
🪟 W-TinyLFU Policy - Two-segment architecture (window + protected) for optimal caching
- Window segment (FIFO) captures recent items
- Protected segment (LFU) keeps frequently accessed items
- Configurable
window_ratiofor workload tuning
-
🎯 Superior Hit Rates - 5-15% better than traditional LRU on mixed workloads
-
🛡️ Cache Pollution Protection - Prevents one-hit wonders from evicting valuable data
-
⚙️ Configurable - Tune
window_ratioto emphasize recency vs frequency
Basic Example:
use cachelito::cache;
// Basic W-TinyLFU cache
#[cache(limit = 1000, policy = "w_tinylfu")]
fn fetch_user_data(user_id: u64) -> UserData {
database.fetch_user(user_id)
}
// Custom window ratio for recency emphasis
#[cache(
limit = 1000,
policy = "w_tinylfu",
window_ratio = 0.3 // 30% window, 70% protected
)]
fn fetch_trending_content(id: u64) -> Content {
api_client.fetch(id)
}How It Works:
W-TinyLFU splits the cache into two segments:
- Window (20% by default): Recent items using FIFO
- Protected (80%): Frequently accessed items using LFU
This dual-segment approach provides excellent performance across various workload patterns.
Configuration Options:
window_ratio(0.01-0.99, default: 0.20) - Balance between recency and frequency- Smaller (0.1-0.15): More emphasis on frequency (stable workloads)
- Larger (0.3-0.4): More emphasis on recency (changing workloads)
Current Status (v0.16.0):
This is the initial, fully functional implementation of W-TinyLFU. Future versions will add:
- Count-Min Sketch admission policy
- Automatic periodic decay
- Segment-specific metrics
Examples:
examples/w_tinylfu.rs- Complete demonstration with multiple scenariostests/w_tinylfu_policy_tests.rs- Test suite
What's Changed
Full Changelog: 0.15.0...0.16.0