From f2f829a2f86fc594a1a647f8adf577391c6252df Mon Sep 17 00:00:00 2001 From: longguancheng Date: Thu, 5 Feb 2026 14:08:39 +0800 Subject: [PATCH] fix short caffeine. --- .../device/service/impl/PayloadServiceImpl.java | 10 ++++------ .../control/SarControlDisconnectStrategy.java | 16 ++++++++-------- .../sar/service/impl/SarControlServiceImpl.java | 8 ++++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/device/service/impl/PayloadServiceImpl.java b/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/device/service/impl/PayloadServiceImpl.java index f5f0e86..8a0ca83 100644 --- a/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/device/service/impl/PayloadServiceImpl.java +++ b/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/device/service/impl/PayloadServiceImpl.java @@ -48,14 +48,14 @@ public class PayloadServiceImpl implements IPayloadService { private ISarControlService sarControlService; private Cache sarPermanentCache; // SAR 专用永久缓存 - private Cache sarShortCache; // 短时状态 + private Cache sarShortCache; // 短时状态 @PostConstruct public void initAndCacheAllSar() { - // 1. 初始化缓存实例(获取“盒子”) + // 初始化缓存实例(获取“盒子”) sarPermanentCache = cacheManager.getCache("device-permanent"); sarShortCache = cacheManager.getCache("sar-short-lived"); - // 2. 防护检查(不抛异常,而是日志 + 降级) + // 防护检查(不抛异常,而是日志 + 降级) if (sarPermanentCache == null) { log.error("device-permanent 缓存未找到!请检查 CacheConfig 是否正确注册"); throw new IllegalStateException("device-permanent 缓存未找到"); @@ -64,12 +64,10 @@ public class PayloadServiceImpl implements IPayloadService { log.error("sar-short-lived 缓存未找到!请检查 CacheConfig"); throw new IllegalStateException("sar-short-lived 缓存未找到"); } - - // 3. 开始缓存所有 SAR(如果 permanentCache 为 null,这里会安全跳过) + // 开始缓存所有 SAR(如果 permanentCache 为 null,这里会安全跳过) PayloadQueryDTO payloadQueryDTO = new PayloadQueryDTO(); payloadQueryDTO.setType(PayloadTypeEnum.SAR.getCode()); List sarList = selectList(payloadQueryDTO); - if (sarPermanentCache != null) { sarList.forEach(this::cacheSar); log.info("SAR 载荷缓存完成,共 {} 条", sarList.size()); diff --git a/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/sar/control/SarControlDisconnectStrategy.java b/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/sar/control/SarControlDisconnectStrategy.java index be5be3a..2040e07 100644 --- a/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/sar/control/SarControlDisconnectStrategy.java +++ b/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/sar/control/SarControlDisconnectStrategy.java @@ -26,13 +26,13 @@ public class SarControlDisconnectStrategy implements ISarControlStrategy { private final CacheManager cacheManager; - private Cache shortCache; - private Cache permanentCache; + private Cache sarShortCache; + private Cache sarPermanentCache; @PostConstruct public void init() { - this.shortCache = cacheManager.getCache("sar-short-lived"); - this.permanentCache = cacheManager.getCache("sar-payload-permanent"); + this.sarShortCache = cacheManager.getCache("sar-short-lived"); + this.sarPermanentCache = cacheManager.getCache("sar-payload-permanent"); } @Override @@ -51,11 +51,11 @@ public class SarControlDisconnectStrategy implements ISarControlStrategy { @Override public void sendPost(SarControlDTO sar) { String connectKey = CacheKey.getSarConnect(sar.getIp()); - if (shortCache != null) { - shortCache.evict(connectKey); + if (sarShortCache != null) { + sarShortCache.evict(connectKey); } - if (permanentCache != null) { - permanentCache.evict(sar.getIp()); + if (sarPermanentCache != null) { + sarPermanentCache.evict(sar.getIp()); } } diff --git a/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/sar/service/impl/SarControlServiceImpl.java b/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/sar/service/impl/SarControlServiceImpl.java index 09c8d59..1d9486c 100644 --- a/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/sar/service/impl/SarControlServiceImpl.java +++ b/backend/Skyeye-sys-dev/skyeye-service-manager/src/main/java/com/zhangy/skyeye/sar/service/impl/SarControlServiceImpl.java @@ -33,12 +33,12 @@ public class SarControlServiceImpl implements ISarControlService { private final CacheManager cacheManager; // final 字段 - private Cache shortCache; + private Cache sarShortCache; @PostConstruct public void init() { - this.shortCache = cacheManager.getCache("sar-short-lived"); - if (shortCache == null) { + this.sarShortCache = cacheManager.getCache("sar-short-lived"); + if (sarShortCache == null) { log.error("sar-short-lived cache 未找到!"); } } @@ -102,6 +102,6 @@ public class SarControlServiceImpl implements ISarControlService { @Override public JmSarStatusDTO getLatestStatus(String ip) { String connectKey = CacheKey.getSarConnect(ip); - return CacheUtil.get(shortCache, connectKey, JmSarStatusDTO.class); + return CacheUtil.get(sarShortCache, connectKey, JmSarStatusDTO.class); } }