mirror of https://gitee.com/stylefeng/roses
【8.3.3】【dict】【cache】更新字典缓存的删除
parent
2d6e1349a4
commit
dd8cf5780d
|
@ -132,21 +132,11 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
|
||||
@Override
|
||||
public void del(DictRequest dictRequest) {
|
||||
|
||||
// 获取字典id的详情
|
||||
SysDict sysDict = this.getById(dictRequest.getDictId());
|
||||
if (sysDict == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除字典id为key的缓存
|
||||
this.dictInfoCache.remove(String.valueOf(dictRequest.getDictId()));
|
||||
|
||||
// 删除字典类型id+字典编码为缓存key的缓存
|
||||
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||
|
||||
// 真实删除字典
|
||||
this.removeById(dictRequest.getDictId());
|
||||
|
||||
// 删除缓存
|
||||
this.deleteDictIdCaches(dictRequest.getDictId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,13 +145,11 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
// 校验字典重复
|
||||
this.validateRepeat(dictRequest, true);
|
||||
|
||||
// 查询旧的字典
|
||||
SysDict sysDict = this.querySysDict(dictRequest);
|
||||
|
||||
// 删除旧的字典的缓存,删除字典类型id+字典编码为缓存key的缓存
|
||||
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||
|
||||
// 删除字典名称缓存
|
||||
this.dictInfoCache.remove(String.valueOf(sysDict.getDictId()));
|
||||
// 删除旧字典名称缓存
|
||||
this.deleteDictIdCaches(sysDict);
|
||||
|
||||
// copy前端的属性
|
||||
BeanUtil.copyProperties(dictRequest, sysDict);
|
||||
|
@ -210,13 +198,10 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
return;
|
||||
}
|
||||
|
||||
list.forEach(sysDict -> {
|
||||
// 删除旧的字典的缓存,删除字典类型id+字典编码为缓存key的缓存
|
||||
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||
|
||||
// 删除字典名称缓存,key是字典id
|
||||
this.dictInfoCache.remove(String.valueOf(sysDict.getDictId()));
|
||||
});
|
||||
// 删除字典名称缓存
|
||||
for (SysDict sysDict : list) {
|
||||
this.deleteDictIdCaches(sysDict);
|
||||
}
|
||||
|
||||
// 删除字典类型下的所有字典
|
||||
this.remove(sysDictLambdaQueryWrapper);
|
||||
|
@ -357,25 +342,11 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
|
||||
@Override
|
||||
public void deleteByDictId(Long dictId) {
|
||||
|
||||
if (dictId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取字典详情
|
||||
SysDict sysDict = this.getById(dictId);
|
||||
if (sysDict == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除字典详情缓存,key是字典id
|
||||
this.dictInfoCache.remove(dictId.toString());
|
||||
|
||||
// 删除旧的字典的缓存,key是字典类型id+字典编码
|
||||
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||
|
||||
// 删除字典记录
|
||||
this.removeById(dictId);
|
||||
|
||||
// 删除字典缓存
|
||||
this.deleteDictIdCaches(dictId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -509,6 +480,24 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchDelete(DictRequest dictRequest) {
|
||||
|
||||
// 获取这一批字典的详情
|
||||
List<SysDict> dictList = this.listByIds(dictRequest.getDictIdList());
|
||||
if (ObjectUtil.isEmpty(dictList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除这一批字典的缓存
|
||||
for (SysDict sysDict : dictList) {
|
||||
this.deleteDictIdCaches(sysDict);
|
||||
}
|
||||
|
||||
// 删除字典
|
||||
this.removeBatchByIds(dictRequest.getDictIdList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详细信息
|
||||
*
|
||||
|
@ -624,27 +613,55 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchDelete(DictRequest dictRequest) {
|
||||
|
||||
// 获取这一批字典的详情
|
||||
List<SysDict> dictList = this.listByIds(dictRequest.getDictIdList());
|
||||
if (ObjectUtil.isEmpty(dictList)) {
|
||||
/**
|
||||
* 删除字典id对应的缓存,目前有3种缓存
|
||||
* <p>
|
||||
* 第一种:key是字典id
|
||||
* 第二种:key是字典类型id + 字典编码
|
||||
* 第三种:key是字典类型编码 + 字典编码
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/1/10 18:02
|
||||
*/
|
||||
private void deleteDictIdCaches(Long dictId) {
|
||||
if (dictId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除这一批字典的缓存
|
||||
for (SysDict sysDict : dictList) {
|
||||
// 获取字典id的详情
|
||||
SysDict sysDict = this.getById(dictId);
|
||||
if (sysDict == null) {
|
||||
return;
|
||||
}
|
||||
this.deleteDictIdCaches(sysDict);
|
||||
}
|
||||
|
||||
// 删除key为字典id的缓存
|
||||
this.dictInfoCache.remove(sysDict.getDictId().toString());
|
||||
|
||||
// 删除旧的字典的缓存,key是字典类型id+字典编码
|
||||
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||
/**
|
||||
* 删除字典id对应的缓存,目前有3种缓存
|
||||
* <p>
|
||||
* 第一种:key是字典id
|
||||
* 第二种:key是字典类型id + 字典编码
|
||||
* 第三种:key是字典类型编码 + 字典编码
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/1/10 18:02
|
||||
*/
|
||||
private void deleteDictIdCaches(SysDict sysDict) {
|
||||
if (sysDict == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除字典
|
||||
this.removeBatchByIds(dictRequest.getDictIdList());
|
||||
// 删除字典id为key的缓存
|
||||
this.dictInfoCache.remove(String.valueOf(sysDict.getDictId()));
|
||||
|
||||
// 删除字典类型id+字典编码为缓存key的缓存
|
||||
this.dictNameMixedCache.remove(sysDict.getDictTypeId() + sysDict.getDictCode());
|
||||
|
||||
// 获取字典类型对应的字典编码
|
||||
SysDictType sysDictType = dictTypeService.getById(sysDict.getDictTypeId());
|
||||
if (sysDictType != null) {
|
||||
this.dictNameMixedCache.remove(sysDictType.getDictTypeCode() + sysDict.getDictCode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue