Skip to main content

Crate wordval_cache

Crate wordval_cache 

Source
Expand description

§wordval-cache

Wordval 缓存抽象:本地内存缓存 + Redis 缓存。

§后端选择

通过配置 cache.type 切换:

  • local — 内存缓存(默认)
  • redis — Redis 缓存(需配置 redis.url,也可用 REDIS_URL 环境变量覆盖)

§作为插件使用

ⓘ
use wordval_cache::CachePlugin;

let mgr = PluginManager::new()
    .add(CachePlugin::new(&config.cache, &config.redis));

§直接使用

ⓘ
use wordval_cache::{create_cache, Cache};

let cache = create_cache(&config.cache, &config.redis).await?;
cache.set("key", &"value").await?;
let val: Option<String> = cache.get("key").await?;

Re-exports§

pub use plugin::CachePlugin;

Modules§

plugin
缓存插件 —— 管理缓存实例的生命周期

Structs§

CacheStats
缓存统计指标
LocalCache
本地内存缓存(DashMap 分片 + ahash + TTL + 统计 + 后台清理)
RedisCache
Redis 缓存实现

Enums§

Error
框架统一错误类型
SharedCache
共享缓存:枚举包装所有缓存实现,供插件与路由层统一使用

Traits§

Cache
统一缓存接口(本地/Redis 实现同一 trait)

Functions§

create_cache
从配置创建共享缓存实例
delete_after
延迟删除单个 key(延迟双删的第二次删除)。
delete_pattern_after
延迟按模式删除(延迟双删的第二次删除,批量 key 场景)。
get_raw
便捷函数:获取原始字节数据
set_raw
便捷函数:设置原始字节数据

Type Aliases§

Result
框架统一 Result 类型