Skip to content

v0.13.0

Choose a tag to compare

@josepdcs josepdcs released this 03 Dec 10:39
· 4 commits to main since this release
871efc7

🎯 Conditional Invalidation with Custom Check Functions!

Version 0.13.0 introduces powerful conditional invalidation, allowing you to selectively invalidate cache entries based on runtime conditions:

New Features:

  • 🎯 Conditional Invalidation - Invalidate entries matching custom check functions (predicates)
  • 🌐 Global Conditional Invalidation Support - Apply check functions across all registered caches
  • 🔑 Key-Based Filtering - Match entries by key patterns, ranges, or any custom logic
  • 🏷️ Named Invalidation Check Functions - Automatic validation on every cache access with invalidate_on = function_name attribute
  • Automatic Registration - All global-scope caches support conditional invalidation by default
  • 🔒 Thread-Safe Execution - Safe concurrent check function execution
  • 💡 Flexible Conditions - Use any Rust logic in your check functions

Quick Start:

use cachelito::{cache, invalidate_with, invalidate_all_with};

// Named invalidation check function (evaluated on every access)
fn is_stale(_key: &String, value: &User) -> bool {
    value.updated_at.elapsed() > Duration::from_secs(3600)
}

#[cache(scope = "global", name = "get_user", invalidate_on = is_stale)]
fn get_user(user_id: u64) -> User {
    fetch_user_from_db(user_id)
}

// Manual conditional invalidation
invalidate_with("get_user", |key| {
    key.parse::<u64>().unwrap_or(0) > 1000
});

// Global invalidation across all caches
invalidate_all_with(|_cache_name, key| {
    key.parse::<u64>().unwrap_or(0) >= 1000
});

See also:

What's Changed

Full Changelog: 0.12.0...0.13.0