first commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package com.starry.admin.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.starry.admin.modules.system.entity.SysDictDataEntity;
|
||||
import com.starry.common.constant.CacheConstants;
|
||||
import com.starry.common.redis.RedisCache;
|
||||
import com.starry.common.utils.SpringUtils;
|
||||
import com.starry.common.utils.StringUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
*/
|
||||
public class DictUtils {
|
||||
|
||||
/**
|
||||
* 获取 cache key
|
||||
*
|
||||
* @param key 参数键
|
||||
* @return 缓存键key
|
||||
*/
|
||||
public static String getCacheKey(String key) {
|
||||
return CacheConstants.SYS_DICT_KEY + key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典缓存
|
||||
*
|
||||
* @param key 参数键
|
||||
* @return dictDatas 字典数据列表
|
||||
*/
|
||||
public static List<SysDictDataEntity> getDictCache(String key) {
|
||||
JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
|
||||
if (StringUtils.isNotNull(arrayCache)) {
|
||||
return arrayCache.toList(SysDictDataEntity.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置字典缓存
|
||||
*
|
||||
* @param key 参数键
|
||||
* @param dataList 字典数据列表
|
||||
*/
|
||||
public static void setDictCache(String key, List<SysDictDataEntity> dataList) {
|
||||
SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dataList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空字典缓存
|
||||
*/
|
||||
public static void clearDictCache() {
|
||||
Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_DICT_KEY + "*");
|
||||
SpringUtils.getBean(RedisCache.class).deleteObject(keys);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user