# unistore-cache
内存缓存能力 - UniStore 能力生态的一部分。
## 功能特性
- **LRU 淘汰**: 基于最近最少使用策略自动淘汰
- **TTL 支持**: 可设置条目过期时间
- **线程安全**: 使用 parking_lot 高性能锁
- **统计信息**: 命中率、大小等缓存统计
- **泛型支持**: 支持任意 Key-Value 类型
## 快速开始
```rust
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");
```
## 配置选项
```rust
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); // 批量淘汰数量
```
## 统计信息
```rust
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