refactor(oauth): replace legacy oauth cache with standard ram cache and add pubsub synchronization

- Replaced custom map-based cache in apps/oauth/cache.go with standard pkg/cache/ram framework.
- Implemented Redis Pub/Sub invalidation channels for distributed token and user cache synchronization.
- Created apps/oauth/cache_test.go to verify local cache operations and pub/sub broadcasts.

refactor(cache): generic RAM cache with CoW and unified preheating

Replaced L2 Redis cache and old cache package with process-local generic pkg/cache/ram. Implemented Copy-on-Write for reads, fine-grained locks per type for writes, and unified preheating in bootstrap. Changed cache invalidation to lazy-loading to resolve SQLite deadlocks during transactions.
This commit is contained in:
ryan
2026-06-27 14:32:27 +08:00
parent 02ebb81929
commit 8d8814b416
7 changed files with 72 additions and 31 deletions
+4
View File
@@ -23,6 +23,10 @@ sidebar: false
### 修复
- 修复由于重构移除系统配置 Redis L2 缓存层后,遗留的系统配置缓存测试用例仍检查 Redis 物理键值导致测试失败的问题:改写测试为验证 L1 RAM 缓存行为,并在失效操作(Invalidate)后引入适当延迟以消除本地 Redis 广播异步被消费带来的测试竞态问题。
- 修复数据库历史迁移代码在重构中丢失了 `tableExistsSQL` 和 `tablesWithPrefixSQL` 辅助函数定义,导致 `internal/db/migrator` 包和 `internal/cmd` 包编译失败的问题:在 `migrator.go` 底部重新实现并补齐了这俩函数的跨数据库方言支持。
- 修复 Agent 包 IP 探测测试中,由于包级别缓存变量 `cachedIP` 跨用例污染导致 `TestLoadFallsBackToLocalIPWhenOutboundLookupFails` 最终获取到上个测试的 cached IP 从而报错失败的问题:在 `nodeip` 包中增加并导出 `ResetCacheForTest` 函数以在测试 Setup/Teardown 中清除缓存状态。
- 修复旧版本迁移升级后,发布版本报错“版本号生成冲突,请重试”的问题。根本原因是配置版本表 `of_config_versions` 的自增主键 `id` 序列与导入的旧数据冲突;现重构配置版本表,将自增 `id` 移除,改由版本号字符串(如 `20260626-003`)直接作为主键(通过迁移 `202606270001_make_version_primary_key` 完成),并同步修改 Agent 和 Flared 模块中的排序及查询条件,解决删除 `id` 列后心跳上报报 `column "id" does not exist` 的故障。
- 修复代理路由详情页点击“发布配置”时,同时弹出配置差异对话框和确认发布对话框导致重叠的问题:点击发布时不再展示配置差异,直接进行确认发布。
- 修复配置版本发布到 Agent 后 `openresty -t` 因 `proxy_cache_path` 使用 `/var/cache/openresty` 导致非 root 用户 `mkdir` 失败的问题:发布快照与渲染将 `/var/` 下路径规范为 `__OPENFLARE_PROXY_CACHE_PATH__`,Agent 应用时落地为 `data_dir/var/cache/openflare_proxy` 并兼容重写已发布配置中的旧路径。