forked from toolchaintechnologycenter/spdm-backend
1、查询任务树列表,先移除缓存,后期再优化
This commit is contained in:
@@ -2577,13 +2577,13 @@ public class ProjectServiceImpl extends BaseService implements IProjectService {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
// 构建缓存key:唯一标识本次查询
|
||||
String cacheKey = "taskTree_" + req.getIdMap().stream().map(t -> t.getKey() + "_" + t.getValue()).collect(Collectors.joining(","));
|
||||
Cache cache = cacheManager.getCache("taskTreeListCache");
|
||||
if (cache != null && cache.get(cacheKey) != null) {
|
||||
// 缓存命中,直接返回,不调用getTaskTree()
|
||||
log.info("--------------------------命中缓存--------------------------");
|
||||
return (List<NodeAllBase>) cache.get(cacheKey).get();
|
||||
}
|
||||
// String cacheKey = "taskTree_" + req.getIdMap().stream().map(t -> t.getKey() + "_" + t.getValue()).collect(Collectors.joining(","));
|
||||
// Cache cache = cacheManager.getCache("taskTreeListCache");
|
||||
// if (cache != null && cache.get(cacheKey) != null) {
|
||||
// // 缓存命中,直接返回,不调用getTaskTree()
|
||||
// log.info("--------------------------命中缓存--------------------------");
|
||||
// return (List<NodeAllBase>) cache.get(cacheKey).get();
|
||||
// }
|
||||
// 缓存未命中,执行原逻辑
|
||||
SdmResponse taskTree = getTaskTree(req);
|
||||
if (taskTree == null || taskTree.getData() == null) {
|
||||
@@ -2598,9 +2598,9 @@ public class ProjectServiceImpl extends BaseService implements IProjectService {
|
||||
}
|
||||
List<NodeAllBase> result = dataList.stream().map(NodeAllBase.class::cast).collect(Collectors.toList());
|
||||
// 存入缓存,设置过期时间(根据业务调整,比如5分钟,避免数据不一致)
|
||||
if (cache != null) {
|
||||
cache.put(cacheKey, result);
|
||||
}
|
||||
// if (cache != null) {
|
||||
// cache.put(cacheKey, result);
|
||||
// }
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user