Skip to content

v0.16.0

Latest

Choose a tag to compare

@josepdcs josepdcs released this 08 Jan 20:07
0a027a1

🪟 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_ratio for 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_ratio to 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:

  1. Window (20% by default): Recent items using FIFO
  2. 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:

What's Changed

  • Add W-TinyLFU (Windowed TinyLFU) policy support by @josepdcs in #37

Full Changelog: 0.15.0...0.16.0