From 46a924ca4678610733a71bf52878d48b7f54d1be Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Wed, 31 Dec 2025 09:14:41 +0800 Subject: [PATCH] feat: warmup now writes to both memory and Redis cache for cross-process sharing --- zhenxun/services/auth_snapshot/service.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/zhenxun/services/auth_snapshot/service.py b/zhenxun/services/auth_snapshot/service.py index 91fbf1f7..fadaab0e 100644 --- a/zhenxun/services/auth_snapshot/service.py +++ b/zhenxun/services/auth_snapshot/service.py @@ -390,6 +390,7 @@ class PluginSnapshotService: """预热所有插件缓存 在启动时调用,预加载所有插件信息到缓存 + 同时写入内存缓存和 Redis 缓存 """ from zhenxun.models.plugin_info import PluginInfo @@ -414,7 +415,22 @@ class PluginSnapshotService: ) cache_key = cls._build_cache_key(plugin.module) + + # 存入内存缓存(最快访问路径) memory_cache.set(cache_key, snapshot) + + # 同时存入 Redis 缓存(跨进程共享) + if cache_config.cache_mode != CacheMode.NONE: + try: + await CacheRoot.set( + CacheType.PLUGIN_SNAPSHOT, + cache_key, + snapshot.model_dump(), + expire=PLUGIN_REDIS_TTL, + ) + except Exception: + pass # Redis 写入失败不影响预热 + count += 1 logger.info(f"已预热 {count} 个插件的快照缓存", LOG_COMMAND)