fix short caffeine.

This commit is contained in:
longguancheng 2026-02-05 14:08:39 +08:00
parent 6ce25eda79
commit f2f829a2f8
3 changed files with 16 additions and 18 deletions

View File

@ -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<SkyeyePayload> sarList = selectList(payloadQueryDTO);
if (sarPermanentCache != null) {
sarList.forEach(this::cacheSar);
log.info("SAR 载荷缓存完成,共 {} 条", sarList.size());

View File

@ -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());
}
}

View File

@ -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);
}
}