refactor: 修改缓存处理逻辑.
This commit is contained in:
@@ -40,13 +40,4 @@ public class AppPreferenceModel implements PreferenceModel {
|
||||
@Schema(description = "菜单宽度")
|
||||
private Number menuWidth;
|
||||
|
||||
@Schema(description = "主机视图")
|
||||
private String hostView;
|
||||
|
||||
@Schema(description = "主机秘钥视图")
|
||||
private String hostKeyView;
|
||||
|
||||
@Schema(description = "主机身份视图")
|
||||
private String hostIdentityView;
|
||||
|
||||
}
|
||||
|
||||
@@ -13,10 +13,6 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class SystemPreferenceStrategy implements IPreferenceStrategy<AppPreferenceModel> {
|
||||
|
||||
private static final String TABLE = "table";
|
||||
|
||||
private static final String CARD = "card";
|
||||
|
||||
@Override
|
||||
public AppPreferenceModel getDefault() {
|
||||
return AppPreferenceModel.builder()
|
||||
@@ -27,9 +23,6 @@ public class SystemPreferenceStrategy implements IPreferenceStrategy<AppPreferen
|
||||
.tabBar(true)
|
||||
.menuWidth(220)
|
||||
.colorWeak(false)
|
||||
.hostView(TABLE)
|
||||
.hostKeyView(CARD)
|
||||
.hostIdentityView(CARD)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@ package com.orion.ops.module.infra.service.impl;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisLists;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisUtils;
|
||||
import com.orion.ops.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.ops.module.infra.convert.DataGroupRelConvert;
|
||||
import com.orion.ops.module.infra.dao.DataGroupDAO;
|
||||
import com.orion.ops.module.infra.dao.DataGroupRelDAO;
|
||||
@@ -189,12 +189,12 @@ public class DataGroupRelServiceImpl implements DataGroupRelService {
|
||||
.then()
|
||||
.list(DataGroupRelConvert.MAPPER::toCache);
|
||||
// 设置屏障 防止穿透
|
||||
RedisStrings.checkBarrier(list, DataGroupRelCacheDTO::new);
|
||||
CacheBarriers.checkBarrier(list, DataGroupRelCacheDTO::new);
|
||||
// 设置缓存
|
||||
RedisStrings.setJson(key, DataGroupCacheKeyDefine.DATA_GROUP_REL_TYPE, list);
|
||||
}
|
||||
// 删除屏障
|
||||
RedisStrings.removeBarrier(list);
|
||||
CacheBarriers.removeBarrier(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -213,15 +213,13 @@ public class DataGroupRelServiceImpl implements DataGroupRelService {
|
||||
.stream()
|
||||
.map(DataGroupRelDO::getRelId)
|
||||
.collect(Collectors.toList());
|
||||
// 添加默认值 防止穿透
|
||||
if (list.isEmpty()) {
|
||||
list.add(Const.NONE_ID);
|
||||
}
|
||||
// 设置屏障 防止穿透
|
||||
CacheBarriers.LONG.check(list);
|
||||
// 设置缓存
|
||||
RedisLists.pushAll(key, DataGroupCacheKeyDefine.DATA_GROUP_REL_GROUP, list, Object::toString);
|
||||
}
|
||||
// 删除默认值
|
||||
list.remove(Const.NONE_ID);
|
||||
// 删除屏障
|
||||
CacheBarriers.LONG.remove(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.enums.MovePosition;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
||||
import com.orion.ops.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.ops.module.infra.convert.DataGroupConvert;
|
||||
import com.orion.ops.module.infra.dao.DataGroupDAO;
|
||||
import com.orion.ops.module.infra.define.cache.DataGroupCacheKeyDefine;
|
||||
@@ -159,12 +160,12 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
.then()
|
||||
.list(DataGroupConvert.MAPPER::toCache);
|
||||
// 设置屏障 防止穿透
|
||||
RedisStrings.checkBarrier(list, DataGroupCacheDTO::new);
|
||||
CacheBarriers.checkBarrier(list, DataGroupCacheDTO::new);
|
||||
// 设置缓存
|
||||
RedisStrings.setJson(key, DataGroupCacheKeyDefine.DATA_GROUP_LIST, list);
|
||||
}
|
||||
// 删除屏障
|
||||
RedisStrings.removeBarrier(list);
|
||||
CacheBarriers.removeBarrier(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -177,7 +178,7 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
// 查询列表缓存
|
||||
List<DataGroupCacheDTO> rows = this.getDataGroupListByCache(type);
|
||||
// 设置屏障 防止穿透
|
||||
RedisStrings.checkBarrier(rows, DataGroupCacheDTO::new);
|
||||
CacheBarriers.checkBarrier(rows, DataGroupCacheDTO::new);
|
||||
if (!Lists.isEmpty(rows)) {
|
||||
// 构建树
|
||||
DataGroupCacheDTO rootNode = DataGroupCacheDTO.builder()
|
||||
@@ -191,7 +192,7 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
RedisStrings.setJson(key, DataGroupCacheKeyDefine.DATA_GROUP_LIST, treeData);
|
||||
}
|
||||
// 删除屏障
|
||||
RedisStrings.removeBarrier(treeData);
|
||||
CacheBarriers.removeBarrier(treeData);
|
||||
return treeData;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisUtils;
|
||||
import com.orion.ops.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.ops.module.infra.convert.DictKeyConvert;
|
||||
import com.orion.ops.module.infra.dao.DictKeyDAO;
|
||||
import com.orion.ops.module.infra.define.cache.DictCacheKeyDefine;
|
||||
@@ -107,13 +108,12 @@ public class DictKeyServiceImpl implements DictKeyService {
|
||||
// 查询数据库
|
||||
list = dictKeyDAO.of().list(DictKeyConvert.MAPPER::toCache);
|
||||
// 设置屏障 防止穿透
|
||||
RedisMaps.checkBarrier(list, DictKeyCacheDTO::new);
|
||||
CacheBarriers.checkBarrier(list, DictKeyCacheDTO::new);
|
||||
// 设置缓存
|
||||
RedisMaps.putAllJson(DictCacheKeyDefine.DICT_KEY.getKey(), s -> s.getId().toString(), list);
|
||||
RedisMaps.setExpire(DictCacheKeyDefine.DICT_KEY);
|
||||
RedisMaps.putAllJson(DictCacheKeyDefine.DICT_KEY, s -> s.getId().toString(), list);
|
||||
}
|
||||
// 删除屏障
|
||||
RedisMaps.removeBarrier(list);
|
||||
CacheBarriers.removeBarrier(list);
|
||||
// 转换
|
||||
return list.stream()
|
||||
.map(DictKeyConvert.MAPPER::to)
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.orion.ops.module.infra.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisLists;
|
||||
import com.orion.ops.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.infra.convert.FavoriteConvert;
|
||||
import com.orion.ops.module.infra.dao.FavoriteDAO;
|
||||
@@ -86,26 +86,24 @@ public class FavoriteServiceImpl implements FavoriteService {
|
||||
Long userId = request.getUserId();
|
||||
String cacheKey = FavoriteCacheKeyDefine.FAVORITE.format(type, userId);
|
||||
// 获取缓存
|
||||
List<Long> cacheRelIdList = RedisLists.range(cacheKey, Long::valueOf);
|
||||
if (cacheRelIdList.isEmpty()) {
|
||||
List<Long> list = RedisLists.range(cacheKey, Long::valueOf);
|
||||
if (list.isEmpty()) {
|
||||
// 条件
|
||||
LambdaQueryWrapper<FavoriteDO> wrapper = this.buildQueryWrapper(request);
|
||||
// 查询数据库
|
||||
cacheRelIdList = favoriteDAO.of(wrapper)
|
||||
list = favoriteDAO.of(wrapper)
|
||||
.stream()
|
||||
.map(FavoriteDO::getRelId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
// 添加默认值 防止穿透
|
||||
if (cacheRelIdList.isEmpty()) {
|
||||
cacheRelIdList.add(Const.NONE_ID);
|
||||
}
|
||||
// 设置屏障 防止穿透
|
||||
CacheBarriers.LONG.check(list);
|
||||
// 设置缓存
|
||||
RedisLists.pushAll(cacheKey, FavoriteCacheKeyDefine.FAVORITE, cacheRelIdList, String::valueOf);
|
||||
RedisLists.pushAll(cacheKey, FavoriteCacheKeyDefine.FAVORITE, list, String::valueOf);
|
||||
}
|
||||
// 删除默认值
|
||||
cacheRelIdList.remove(Const.NONE_ID);
|
||||
return cacheRelIdList;
|
||||
// 删除屏障
|
||||
CacheBarriers.LONG.remove(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisUtils;
|
||||
import com.orion.ops.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.infra.convert.SystemUserConvert;
|
||||
import com.orion.ops.module.infra.dao.OperatorLogDAO;
|
||||
@@ -164,13 +165,12 @@ public class SystemUserServiceImpl implements SystemUserService {
|
||||
// 查询数据库
|
||||
list = systemUserDAO.of().list(SystemUserConvert.MAPPER::toUserInfo);
|
||||
// 设置屏障 防止穿透
|
||||
RedisMaps.checkBarrier(list, UserInfoDTO::new);
|
||||
CacheBarriers.checkBarrier(list, UserInfoDTO::new);
|
||||
// 设置缓存
|
||||
RedisMaps.putAllJson(UserCacheKeyDefine.USER_LIST.getKey(), s -> s.getId().toString(), list);
|
||||
RedisMaps.setExpire(UserCacheKeyDefine.USER_LIST);
|
||||
RedisMaps.putAllJson(UserCacheKeyDefine.USER_LIST, s -> s.getId().toString(), list);
|
||||
}
|
||||
// 删除屏障
|
||||
RedisMaps.removeBarrier(list);
|
||||
CacheBarriers.removeBarrier(list);
|
||||
// 转换
|
||||
return list.stream()
|
||||
.map(SystemUserConvert.MAPPER::to)
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.orion.ops.module.infra.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.mybatis.core.query.Conditions;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisLists;
|
||||
import com.orion.ops.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.ops.module.infra.convert.TagConvert;
|
||||
import com.orion.ops.module.infra.dao.TagDAO;
|
||||
import com.orion.ops.module.infra.define.cache.TagCacheKeyDefine;
|
||||
@@ -69,13 +69,12 @@ public class TagServiceImpl implements TagService {
|
||||
LambdaQueryWrapper<TagDO> wrapper = Conditions.eq(TagDO::getType, type);
|
||||
list = tagDAO.of(wrapper).list(TagConvert.MAPPER::toCache);
|
||||
// 设置屏障 防止穿透
|
||||
RedisLists.checkBarrier(list, TagCacheDTO::new);
|
||||
CacheBarriers.checkBarrier(list, TagCacheDTO::new);
|
||||
// 设置到缓存
|
||||
RedisLists.pushAllJson(cacheKey, list);
|
||||
RedisLists.setExpire(cacheKey, TagCacheKeyDefine.TAG_NAME);
|
||||
RedisLists.pushAllJson(cacheKey, TagCacheKeyDefine.TAG_NAME, list);
|
||||
}
|
||||
// 删除屏障
|
||||
RedisLists.removeBarrier(list);
|
||||
CacheBarriers.removeBarrier(list);
|
||||
// 转换
|
||||
return list.stream()
|
||||
.map(TagConvert.MAPPER::to)
|
||||
|
||||
@@ -23,8 +23,7 @@ public class TipsServiceImpl implements TipsService {
|
||||
public void tipped(String tippedKey) {
|
||||
Long userId = SecurityUtils.getLoginUserId();
|
||||
String key = TipsCacheKeyDefine.TIPS.format(userId);
|
||||
RedisLists.push(key, tippedKey);
|
||||
RedisLists.setExpire(key, TipsCacheKeyDefine.TIPS);
|
||||
RedisLists.push(key, TipsCacheKeyDefine.TIPS, tippedKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user