修改缓存逻辑.
This commit is contained in:
@@ -20,14 +20,14 @@ public interface HostCacheKeyDefine {
|
||||
.key("host:key:list")
|
||||
.desc("主机秘钥列表")
|
||||
.type(HostKeyCacheDTO.class)
|
||||
.timeout(3, TimeUnit.DAYS)
|
||||
.timeout(1, TimeUnit.HOURS)
|
||||
.build();
|
||||
|
||||
CacheKeyDefine HOST_IDENTITY = new CacheKeyBuilder()
|
||||
.key("host:identity:list")
|
||||
.desc("主机身份列表")
|
||||
.type(HostIdentityCacheDTO.class)
|
||||
.timeout(3, TimeUnit.DAYS)
|
||||
.timeout(1, TimeUnit.HOURS)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@@ -28,4 +28,7 @@ public class HostIdentityCacheDTO implements Serializable {
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.security.PasswordModifier;
|
||||
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.RedisMaps;
|
||||
import com.orion.ops.module.asset.convert.HostIdentityConvert;
|
||||
import com.orion.ops.module.asset.dao.HostIdentityDAO;
|
||||
import com.orion.ops.module.asset.dao.HostKeyDAO;
|
||||
@@ -60,11 +60,9 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
// 插入
|
||||
int effect = hostIdentityDAO.insert(record);
|
||||
log.info("HostIdentityService-createHostIdentity effect: {}", effect);
|
||||
Long id = record.getId();
|
||||
// 设置缓存
|
||||
RedisLists.pushJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(record));
|
||||
RedisLists.setExpire(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
return id;
|
||||
// 删除缓存
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
return record.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,12 +86,12 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
.set(HostIdentityDO::getKeyId, request.getKeyId())
|
||||
.eq(HostIdentityDO::getId, id);
|
||||
int effect = hostIdentityDAO.update(updateRecord, wrapper);
|
||||
// 设置缓存
|
||||
if (!record.getName().equals(updateRecord.getName())) {
|
||||
RedisLists.removeJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(record));
|
||||
RedisLists.pushJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(updateRecord));
|
||||
}
|
||||
log.info("HostIdentityService-updateHostIdentityById effect: {}", effect);
|
||||
// 删除缓存
|
||||
if (!record.getName().equals(updateRecord.getName()) ||
|
||||
!record.getUsername().equals(updateRecord.getUsername())) {
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
}
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -109,7 +107,7 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
@Override
|
||||
public List<HostIdentityVO> getHostIdentityList() {
|
||||
// 查询缓存
|
||||
List<HostIdentityCacheDTO> list = RedisLists.rangeJson(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
List<HostIdentityCacheDTO> list = RedisMaps.valuesJson(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
if (list.isEmpty()) {
|
||||
// 查询数据库
|
||||
list = hostIdentityDAO.of().list(HostIdentityConvert.MAPPER::toCache);
|
||||
@@ -120,8 +118,8 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
.build());
|
||||
}
|
||||
// 设置缓存
|
||||
RedisLists.pushAllJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), list);
|
||||
RedisLists.setExpire(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
RedisMaps.putAllJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), s -> s.getId().toString(), list);
|
||||
RedisMaps.setExpire(HostCacheKeyDefine.HOST_IDENTITY);
|
||||
}
|
||||
// 删除默认值
|
||||
return list.stream()
|
||||
@@ -173,7 +171,7 @@ public class HostIdentityServiceImpl implements HostIdentityService {
|
||||
// TODO config
|
||||
|
||||
// 删除缓存
|
||||
RedisLists.removeJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(record));
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_IDENTITY.getKey(), record.getId());
|
||||
log.info("HostIdentityService-deleteHostIdentityById effect: {}", effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.security.PasswordModifier;
|
||||
import com.orion.ops.framework.common.utils.CryptoUtils;
|
||||
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.RedisMaps;
|
||||
import com.orion.ops.module.asset.convert.HostKeyConvert;
|
||||
import com.orion.ops.module.asset.dao.HostIdentityDAO;
|
||||
import com.orion.ops.module.asset.dao.HostKeyDAO;
|
||||
@@ -63,9 +63,8 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
int effect = hostKeyDAO.insert(record);
|
||||
log.info("HostKeyService-createHostKey effect: {}", effect);
|
||||
Long id = record.getId();
|
||||
// 设置缓存
|
||||
RedisLists.pushJson(HostCacheKeyDefine.HOST_KEY.getKey(), HostKeyConvert.MAPPER.toCache(record));
|
||||
RedisLists.setExpire(HostCacheKeyDefine.HOST_KEY);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_KEY);
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -87,10 +86,9 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
updateRecord.setPassword(newPassword);
|
||||
// 更新
|
||||
int effect = hostKeyDAO.updateById(updateRecord);
|
||||
// 设置缓存
|
||||
// 删除缓存
|
||||
if (!record.getName().equals(updateRecord.getName())) {
|
||||
RedisLists.removeJson(HostCacheKeyDefine.HOST_KEY.getKey(), HostKeyConvert.MAPPER.toCache(record));
|
||||
RedisLists.pushJson(HostCacheKeyDefine.HOST_KEY.getKey(), HostKeyConvert.MAPPER.toCache(updateRecord));
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_KEY);
|
||||
}
|
||||
log.info("HostKeyService-updateHostKeyById effect: {}", effect);
|
||||
return effect;
|
||||
@@ -124,7 +122,7 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
@Override
|
||||
public List<HostKeyVO> getHostKeyList() {
|
||||
// 查询缓存
|
||||
List<HostKeyCacheDTO> list = RedisLists.rangeJson(HostCacheKeyDefine.HOST_KEY);
|
||||
List<HostKeyCacheDTO> list = RedisMaps.valuesJson(HostCacheKeyDefine.HOST_KEY);
|
||||
if (list.isEmpty()) {
|
||||
// 查询数据库
|
||||
list = hostKeyDAO.of().list(HostKeyConvert.MAPPER::toCache);
|
||||
@@ -135,8 +133,8 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
.build());
|
||||
}
|
||||
// 设置缓存
|
||||
RedisLists.pushAllJson(HostCacheKeyDefine.HOST_KEY.getKey(), list);
|
||||
RedisLists.setExpire(HostCacheKeyDefine.HOST_KEY);
|
||||
RedisMaps.putAllJson(HostCacheKeyDefine.HOST_KEY.getKey(), s -> s.getId().toString(), list);
|
||||
RedisMaps.setExpire(HostCacheKeyDefine.HOST_KEY);
|
||||
}
|
||||
// 删除默认值
|
||||
return list.stream()
|
||||
@@ -171,7 +169,7 @@ public class HostKeyServiceImpl implements HostKeyService {
|
||||
// TODO config
|
||||
|
||||
// 删除缓存
|
||||
RedisLists.removeJson(HostCacheKeyDefine.HOST_KEY.getKey(), HostKeyConvert.MAPPER.toCache(record));
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_KEY.getKey(), record.getId());
|
||||
log.info("HostKeyService-deleteHostKeyById effect: {}", effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user