unistore-cache

Crates.iounistore-cache
lib.rsunistore-cache
version0.1.0
created_at2026-01-20 11:03:47.014912+00
updated_at2026-01-20 11:03:47.014912+00
descriptionIn-memory cache capability for UniStore
homepagehttps://github.com/yangbo1317/unistore
repositoryhttps://github.com/yangbo1317/unistore
max_upload_size
id2056355
size45,181
(yangbo1317)

documentation

https://docs.rs/unistore-cache

README

unistore-cache

内存缓存能力 - UniStore 能力生态的一部分。

功能特性

  • LRU 淘汰: 基于最近最少使用策略自动淘汰
  • TTL 支持: 可设置条目过期时间
  • 线程安全: 使用 parking_lot 高性能锁
  • 统计信息: 命中率、大小等缓存统计
  • 泛型支持: 支持任意 Key-Value 类型

快速开始

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

Commit count: 0

cargo fmt