use std::time::Duration;
use cachet::{Cache, CacheEntry};
use tick::Clock;
#[tokio::main]
async fn main() {
let clock = Clock::new_tokio();
let cache = Cache::builder::<String, String>(clock)
.memory()
.enable_logs()
.ttl(Duration::from_secs(30))
.build();
let key = "user:1".to_string();
cache
.insert(key.clone(), CacheEntry::new("Alice".to_string()))
.await
.expect("insert failed");
println!("insert: ok");
let hit = cache.get(&key).await.expect("get failed");
match hit {
Some(e) => println!("get (hit): {}", e.value()),
None => println!("get (hit): not found"),
}
let miss = cache.get(&"missing".to_string()).await.expect("get failed");
match miss {
Some(e) => println!("get (miss): {}", e.value()),
None => println!("get (miss): not found"),
}
}