取消缓存
This commit is contained in:
@@ -48,14 +48,5 @@ public interface IComSchTreeService {
|
|||||||
|
|
||||||
Map<Integer,List<SelectIntVO>> getSchGroupTypeList(Integer schId, int type);
|
Map<Integer,List<SelectIntVO>> getSchGroupTypeList(Integer schId, int type);
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除全部缓存(Redis 组树/学校列表 + 本地内存缓存)
|
|
||||||
*/
|
|
||||||
void clearCache();
|
void clearCache();
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除指定学校的缓存(学校组树 + 全局缓存)
|
|
||||||
* @param schId 学校ID,为 null 时等同清除全部
|
|
||||||
*/
|
|
||||||
void clearCache(Integer schId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,18 +80,6 @@ public class ComSchTreeService implements IComSchTreeService {
|
|||||||
idToNameCache = null;
|
idToNameCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除指定学校的缓存(学校组树 + 全局缓存)
|
|
||||||
* @param schId 学校ID,为 null 时等同清除全部
|
|
||||||
*/
|
|
||||||
public void clearCache(Integer schId) {
|
|
||||||
if (schId != null) {
|
|
||||||
redisUtil.del(RedisConstants.SCHOOL_TREE + "_" + schId);
|
|
||||||
}
|
|
||||||
// 学校树变更可能影响学校列表/全局组树,一并清除
|
|
||||||
clearCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取基础学制映射(带双重检查锁)
|
* 获取基础学制映射(带双重检查锁)
|
||||||
*/
|
*/
|
||||||
@@ -129,16 +117,6 @@ public class ComSchTreeService implements IComSchTreeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// public List<BoaGroup> getSchTree(Integer schId) {
|
|
||||||
// BoaGroup group = YschBaseOpenApi.getGroupById(schId,true);
|
|
||||||
// return Collections.singletonList(group);
|
|
||||||
//// String cacheKey = RedisConstants.SCHOOL_TREE + "_" + schId;
|
|
||||||
//// String json = redisUtil.get(cacheKey,String.class);
|
|
||||||
//// List<BoaGroup> treeList = OtherUtil.jsonParseArrayTree(json, BoaGroup.class);
|
|
||||||
//// return treeList;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
public String getSchoolName(Integer schId) {
|
public String getSchoolName(Integer schId) {
|
||||||
if (schId == null) {
|
if (schId == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -270,31 +248,8 @@ public class ComSchTreeService implements IComSchTreeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<BoaGroup> getSchTree(Integer schId) {
|
public List<BoaGroup> getSchTree(Integer schId) {
|
||||||
String cacheKey= RedisConstants.SCHOOL_TREE+"_"+schId;
|
|
||||||
List<BoaGroup> cached = redisUtil.getList(cacheKey, BoaGroup.class);
|
|
||||||
if (cached != null && !cached.isEmpty()) {
|
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 加锁防止缓存击穿 + 双重检查
|
|
||||||
synchronized (this) {
|
|
||||||
cached = redisUtil.getList(cacheKey, BoaGroup.class);
|
|
||||||
if (cached != null && !cached.isEmpty()) {
|
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 从数据库查询
|
|
||||||
BoaGroup schGroup = YschBaseOpenApi.getGroupById(schId,true);
|
BoaGroup schGroup = YschBaseOpenApi.getGroupById(schId,true);
|
||||||
List<BoaGroup> list=Collections.singletonList(schGroup);
|
return Collections.singletonList(schGroup);
|
||||||
|
|
||||||
// 4. 仅缓存非空结果;空结果不缓存,防止空缓存污染(穿透风险可忽略)
|
|
||||||
if (!list.isEmpty()) {
|
|
||||||
redisUtil.set(cacheKey,list, RedisConstants.CACHE_EXPIRE_1M);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SelectIntVO> getSchoolList() {
|
public List<SelectIntVO> getSchoolList() {
|
||||||
|
|||||||
Reference in New Issue
Block a user