use std::time::Duration;
use cachet::{Cache, CacheEntry, FallbackPromotionPolicy};
use cachet_tier::MockCache;
use tick::Clock;
#[tokio::main]
async fn main() {
let clock = Clock::new_tokio();
let l2_storage = MockCache::<String, String>::new();
let l2 = Cache::builder::<String, String>(clock.clone())
.storage(l2_storage)
.ttl(Duration::from_secs(600));
let cache = Cache::builder::<String, String>(clock)
.memory()
.ttl(Duration::from_secs(60))
.fallback(l2)
.promotion_policy(FallbackPromotionPolicy::always())
.build();
cache
.insert("key".to_string(), CacheEntry::new("value".to_string()))
.await
.expect("insert failed");
let v = cache.get(&"key".to_string()).await.expect("get failed");
match v {
Some(e) => println!("get(key): {}", e.value()),
None => println!("get(key): not found"),
}
}