use futures::FutureExt;
use crate::{
autocache::AutoCache,
local_cache::{LocalCache, LocalCacheOption},
};
fn on_metrics(_method: &str, _is_error: bool, _ns: &str, _from: &str, _cache_name: &str) {}
#[derive(Debug, Clone)]
struct Item {
count: u32,
message: String,
}
#[tokio::test]
async fn test_builder() {
tracing_subscriber::fmt::init();
let ac = AutoCache::builder()
.cache(LocalCache::new(LocalCacheOption {
segments: 8,
max_capacity: 64,
..Default::default()
}))
.expire_time(std::time::Duration::from_secs(10))
.use_expired_data(true)
.on_metrics(on_metrics)
.single_loader(|key: String, ()| {
async move {
dbg!(&key);
if key == "test-key4" {
return Ok(None);
}
Ok(Some(Item {
count: 1,
message: key.clone(),
}))
}
.boxed()
})
.build();
let v1 = ac.mget(&[("test-key1".to_string(), ())]).await.unwrap();
dbg!(&v1);
}