fix short caffeine.
This commit is contained in:
parent
6ce25eda79
commit
f2f829a2f8
@ -52,10 +52,10 @@ public class PayloadServiceImpl implements IPayloadService {
|
|||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initAndCacheAllSar() {
|
public void initAndCacheAllSar() {
|
||||||
// 1. 初始化缓存实例(获取“盒子”)
|
// 初始化缓存实例(获取“盒子”)
|
||||||
sarPermanentCache = cacheManager.getCache("device-permanent");
|
sarPermanentCache = cacheManager.getCache("device-permanent");
|
||||||
sarShortCache = cacheManager.getCache("sar-short-lived");
|
sarShortCache = cacheManager.getCache("sar-short-lived");
|
||||||
// 2. 防护检查(不抛异常,而是日志 + 降级)
|
// 防护检查(不抛异常,而是日志 + 降级)
|
||||||
if (sarPermanentCache == null) {
|
if (sarPermanentCache == null) {
|
||||||
log.error("device-permanent 缓存未找到!请检查 CacheConfig 是否正确注册");
|
log.error("device-permanent 缓存未找到!请检查 CacheConfig 是否正确注册");
|
||||||
throw new IllegalStateException("device-permanent 缓存未找到");
|
throw new IllegalStateException("device-permanent 缓存未找到");
|
||||||
@ -64,12 +64,10 @@ public class PayloadServiceImpl implements IPayloadService {
|
|||||||
log.error("sar-short-lived 缓存未找到!请检查 CacheConfig");
|
log.error("sar-short-lived 缓存未找到!请检查 CacheConfig");
|
||||||
throw new IllegalStateException("sar-short-lived 缓存未找到");
|
throw new IllegalStateException("sar-short-lived 缓存未找到");
|
||||||
}
|
}
|
||||||
|
// 开始缓存所有 SAR(如果 permanentCache 为 null,这里会安全跳过)
|
||||||
// 3. 开始缓存所有 SAR(如果 permanentCache 为 null,这里会安全跳过)
|
|
||||||
PayloadQueryDTO payloadQueryDTO = new PayloadQueryDTO();
|
PayloadQueryDTO payloadQueryDTO = new PayloadQueryDTO();
|
||||||
payloadQueryDTO.setType(PayloadTypeEnum.SAR.getCode());
|
payloadQueryDTO.setType(PayloadTypeEnum.SAR.getCode());
|
||||||
List<SkyeyePayload> sarList = selectList(payloadQueryDTO);
|
List<SkyeyePayload> sarList = selectList(payloadQueryDTO);
|
||||||
|
|
||||||
if (sarPermanentCache != null) {
|
if (sarPermanentCache != null) {
|
||||||
sarList.forEach(this::cacheSar);
|
sarList.forEach(this::cacheSar);
|
||||||
log.info("SAR 载荷缓存完成,共 {} 条", sarList.size());
|
log.info("SAR 载荷缓存完成,共 {} 条", sarList.size());
|
||||||
|
|||||||
@ -26,13 +26,13 @@ public class SarControlDisconnectStrategy implements ISarControlStrategy {
|
|||||||
|
|
||||||
private final CacheManager cacheManager;
|
private final CacheManager cacheManager;
|
||||||
|
|
||||||
private Cache shortCache;
|
private Cache sarShortCache;
|
||||||
private Cache permanentCache;
|
private Cache sarPermanentCache;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
this.shortCache = cacheManager.getCache("sar-short-lived");
|
this.sarShortCache = cacheManager.getCache("sar-short-lived");
|
||||||
this.permanentCache = cacheManager.getCache("sar-payload-permanent");
|
this.sarPermanentCache = cacheManager.getCache("sar-payload-permanent");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -51,11 +51,11 @@ public class SarControlDisconnectStrategy implements ISarControlStrategy {
|
|||||||
@Override
|
@Override
|
||||||
public void sendPost(SarControlDTO sar) {
|
public void sendPost(SarControlDTO sar) {
|
||||||
String connectKey = CacheKey.getSarConnect(sar.getIp());
|
String connectKey = CacheKey.getSarConnect(sar.getIp());
|
||||||
if (shortCache != null) {
|
if (sarShortCache != null) {
|
||||||
shortCache.evict(connectKey);
|
sarShortCache.evict(connectKey);
|
||||||
}
|
}
|
||||||
if (permanentCache != null) {
|
if (sarPermanentCache != null) {
|
||||||
permanentCache.evict(sar.getIp());
|
sarPermanentCache.evict(sar.getIp());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,12 +33,12 @@ public class SarControlServiceImpl implements ISarControlService {
|
|||||||
|
|
||||||
private final CacheManager cacheManager; // final 字段
|
private final CacheManager cacheManager; // final 字段
|
||||||
|
|
||||||
private Cache shortCache;
|
private Cache sarShortCache;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
this.shortCache = cacheManager.getCache("sar-short-lived");
|
this.sarShortCache = cacheManager.getCache("sar-short-lived");
|
||||||
if (shortCache == null) {
|
if (sarShortCache == null) {
|
||||||
log.error("sar-short-lived cache 未找到!");
|
log.error("sar-short-lived cache 未找到!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,6 +102,6 @@ public class SarControlServiceImpl implements ISarControlService {
|
|||||||
@Override
|
@Override
|
||||||
public JmSarStatusDTO getLatestStatus(String ip) {
|
public JmSarStatusDTO getLatestStatus(String ip) {
|
||||||
String connectKey = CacheKey.getSarConnect(ip);
|
String connectKey = CacheKey.getSarConnect(ip);
|
||||||
return CacheUtil.get(shortCache, connectKey, JmSarStatusDTO.class);
|
return CacheUtil.get(sarShortCache, connectKey, JmSarStatusDTO.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user