| Crates.io | unistore-cache |
| lib.rs | unistore-cache |
| version | 0.1.0 |
| created_at | 2026-01-20 11:03:47.014912+00 |
| updated_at | 2026-01-20 11:03:47.014912+00 |
| description | In-memory cache capability for UniStore |
| homepage | https://github.com/yangbo1317/unistore |
| repository | https://github.com/yangbo1317/unistore |
| max_upload_size | |
| id | 2056355 |
| size | 45,181 |
内存缓存能力 - UniStore 能力生态的一部分。
use unistore_cache::{Cache, CacheConfig};
use std::time::Duration;
// 创建缓存
let cache = Cache::new(CacheConfig::default()
.max_capacity(1000)
.default_ttl(Duration::from_secs(300)));
// 存取数据
cache.insert("key1", "value1");
let value = cache.get(&"key1");
use unistore_cache::CacheConfig;
use std::time::Duration;
let config = CacheConfig::default()
.max_capacity(10000) // 最大条目数
.default_ttl(Duration::from_secs(3600)) // 默认 TTL
.eviction_batch_size(100); // 批量淘汰数量
let stats = cache.stats();
println!("命中率: {:.2}%", stats.hit_rate() * 100.0);
println!("当前大小: {}", stats.size);
println!("总命中: {}", stats.hits);
println!("总未命中: {}", stats.misses);
MIT OR Apache-2.0