fix 修正 spring cache 获取在线用户失败问题, 回退为使用 redis 工具缓存 ;

update 优化 DictUtils, 使用 CacheUtils 缓存字典数据 ;
This commit is contained in:
zlyx
2022-08-30 12:36:18 +08:00
parent 4c48108625
commit cb1e93d3f5
3 changed files with 16 additions and 37 deletions

View File

@@ -1,11 +1,9 @@
package com.ruoyi.common.dict.utils;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.redis.utils.RedisUtils;
import com.ruoyi.common.core.constant.CacheNames;
import com.ruoyi.common.redis.utils.CacheUtils;
import com.ruoyi.system.api.domain.SysDictData;
import java.util.Collection;
import java.util.List;
/**
@@ -21,7 +19,7 @@ public class DictUtils {
* @param dictDatas 字典数据列表
*/
public static void setDictCache(String key, List<SysDictData> dictDatas) {
RedisUtils.setCacheObject(getCacheKey(key), dictDatas);
CacheUtils.put(CacheNames.SYS_DICT, key, dictDatas);
}
/**
@@ -31,11 +29,7 @@ public class DictUtils {
* @return dictDatas 字典数据列表
*/
public static List<SysDictData> getDictCache(String key) {
List<SysDictData> dictDatas = RedisUtils.getCacheObject(getCacheKey(key));
if (ObjectUtil.isNotNull(dictDatas)) {
return dictDatas;
}
return null;
return CacheUtils.get(CacheNames.SYS_DICT, key);
}
/**
@@ -44,24 +38,14 @@ public class DictUtils {
* @param key 字典键
*/
public static void removeDictCache(String key) {
RedisUtils.deleteObject(getCacheKey(key));
CacheUtils.evict(CacheNames.SYS_DICT, key);
}
/**
* 清空字典缓存
*/
public static void clearDictCache() {
Collection<String> keys = RedisUtils.keys(CacheConstants.SYS_DICT_KEY + "*");
RedisUtils.deleteObject(keys);
CacheUtils.clear(CacheNames.SYS_DICT);
}
/**
* 设置cache key
*
* @param configKey 参数键
* @return 缓存键key
*/
public static String getCacheKey(String configKey) {
return CacheConstants.SYS_DICT_KEY + configKey;
}
}