v0.15.0
⏰ TLRU (Time-aware Least Recently Used) Policy!
Version 0.15.0 introduces the TLRU eviction policy, combining recency, frequency, and time-based factors for intelligent cache management:
New Features:
- ⏰ TLRU Policy - Time-aware LRU that considers age, frequency, and recency
- 🎯 Smart Eviction - Prioritizes entries approaching TTL expiration
- 📊 Triple Scoring - Combines
frequency × position_weight × age_factor - 🎚️ Frequency Weight - NEW:
frequency_weightparameter to fine-tune recency vs frequency balance - 🔄 Automatic Aging - Entries close to TTL get lower priority
- 💡 Backward Compatible - Without TTL, behaves like ARC
- ⚡ Optimal for Time-Sensitive Data - Perfect for caches with expiring content
Quick Start:
use cachelito::cache;
// Time-aware caching with TLRU
#[cache(policy = "tlru", limit = 100, ttl = 300)]
fn fetch_weather(city: String) -> WeatherData {
// Entries approaching 5-minute TTL are prioritized for eviction
fetch_from_api(city)
}
// TLRU without TTL behaves like ARC
#[cache(policy = "tlru", limit = 50)]
fn compute_expensive(n: u64) -> u64 {
// Considers both frequency and recency
expensive_calculation(n)
}
// NEW: Fine-tune with frequency_weight
#[cache(policy = "tlru", limit = 100, ttl = 300, frequency_weight = 1.5)]
fn fetch_popular_content(id: u64) -> Content {
// frequency_weight > 1.0 emphasizes frequency over recency
// Popular entries stay cached longer
database.fetch(id)
}How TLRU Works:
- Score Formula:
frequency^weight × position_weight × age_factor - Frequency Weight: Control balance between recency and frequency (default = 1.0)
< 1.0: Emphasize recency (good for time-sensitive data)> 1.0: Emphasize frequency (good for popular content)
- Age Factor: Decreases as entry approaches TTL expiration (0.0 = expired, 1.0 = fresh)
- Eviction: Lowest score = first to evict
- Best For: Time-sensitive data, mixed access patterns, expiring content
What's Changed
Full Changelog: 0.14.0...0.15.0