use std::time::Duration;
use cachet::{Cache, CacheEntry};
use tick::Clock;
#[tokio::main]
async fn main() {
let clock = Clock::new_tokio();
let l2 = Cache::builder::<String, String>(clock.clone())
.memory()
.ttl(Duration::from_secs(300));
let cache = Cache::builder::<String, String>(clock)
.memory()
.ttl(Duration::from_secs(60))
.fallback(l2)
.build();
let key = "user:1".to_string();
cache
.insert(key.clone(), CacheEntry::new("Alice".to_string()))
.await
.expect("insert failed");
let value = cache.get(&key).await.expect("get failed");
match value {
Some(e) => println!("get({key}): {}", e.value()),
None => println!("get({key}): not found"),
}
cache.invalidate(&key).await.expect("invalidate failed");
let value = cache.get(&key).await.expect("get failed");
assert!(value.is_none(), "entry should be gone from both tiers");
}