modify: 清除diskcache依赖

This commit is contained in:
2026-09-04 14:50:34 +08:00
parent eaf4089b6f
commit 93be99141f
15 changed files with 522 additions and 88 deletions
+24 -8
View File
@@ -150,14 +150,30 @@ tokio::runtime::Builder::new_multi_thread().enable_all().build()?.block_on(async
### 5.2 多实例共享缓存 `[workers.cache]`
多实例部署(多进程/多机)**必须**启用 Redis 共享缓存,使副本数与配置跨实例收敛为单一事实来源:
Rust 进程插件支持两种共享缓存后端(schema 与 Python `chongming-cache` 完全一致):
```toml
[workers.cache]
backend = "redis" # 仅支持 redis(Python 本地 diskcache 格式 Rust 不可读)
url = "redis://127.0.0.1:6379/0"
launch_worker_count = "cache" # 缓存为 count 单一事实来源
```
1. **本机共享 `sqlite`(feature `local-cache`)**:同一份 SQLite 文件由 Python 与 Rust 读写,
实现单机多实例/跨语言收敛,无需 Redis。需 `cargo build --features local-cache`:
```toml
[workers.cache]
backend = "sqlite" # schema 与 Python SqliteBackend 一致(旧名 diskcache 兼容)
path = "./cache_data/cache.db" # 与网关该实例 `[cache].path` 指向同一文件
launch_worker_count = "cache"
```
2. **跨主机 `redis`(feature `redis-cache`)**:多机部署必须用 Redis 共享缓存:
```toml
[workers.cache]
backend = "redis"
url = "redis://127.0.0.1:6379/0"
prefix = "chongming:" # 与网关 config.toml [cache].redis_prefix 对齐(缺省空)
launch_worker_count = "cache"
```
未指定 backend(缺省)时 Rust 走 `Cache::None`,退化为本地 toml 语义。
> `prefix` 必须与网关 `[cache].redis_prefix`(如 `"chongming:"`)一致,Rust 插件才会读写
> 与网关同一批共享键。若网关未设前缀可省略。缓存值统一以 JSON 存储(Python 侧用
> orjson、Rust 侧用 serde_json),**任意键**均可跨语言互通;与 Rust 共享的键请使用
> JSON 兼容类型(dict/list/int/str/bool/null)。
编译启用:`bash build.sh dist "redis-cache"`(或 Cargo 依赖加 `chongming-worker-rs/redis-cache`)。
未配置时单实例直接读写本地 `config.toml`(默认无缓存),行为一致。
@@ -268,7 +284,7 @@ unzip myplugin.zip -d /app && cd /app && ./start.sh
| 契约校验 | Python 进程内三方校验(硬失败);Rust 为**发布前自检**:无 handler 端点告警跳过,不发布残缺路由 |
| 模型生成 | Rust 用 gen_models 生成强类型结构体 + **启动时指纹校验**(TOML 变更未重生成即告警,比 Python 更强) |
| handler 注入 | worker_id 经 `Request.worker_id`、user_info 经 `Request.user_info` 注入(非函数参数) |
| 配置缓存后端 | Rust 仅 Redis(无法读 Python 本地 diskcache);单实例走无缓存回退 |
| 配置缓存后端 | Rust 支持 sqlite(`local-cache`,本机与 Python 共享同一 .db)+ Redis(`redis-cache`,跨主机);缺省无缓存回退 |
| 数据库 | Rust 走 sqlx(见 §7),配置键与 Python `chongming_database` 对齐 |
---