v0.13.0
🎯 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_nameattribute - ⚡ 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:
examples/conditional_invalidation.rs- Manual conditional invalidationexamples/named_invalidation.rs- Named invalidation check functions
What's Changed
Full Changelog: 0.12.0...0.13.0