mirror of https://gitee.com/stylefeng/roses
【8.3.3】【dict】【cache】删除和更新字典时候,更新缓存内容
parent
f0fbaa8513
commit
080760174a
|
@ -1,4 +1,4 @@
|
|||
package cn.stylefeng.roses.kernel.dict.modular.cache;
|
||||
package cn.stylefeng.roses.kernel.dict.modular.cache.dictname;
|
||||
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
|
|
@ -1,4 +1,4 @@
|
|||
package cn.stylefeng.roses.kernel.dict.modular.cache;
|
||||
package cn.stylefeng.roses.kernel.dict.modular.cache.dictname;
|
||||
|
||||
import cn.stylefeng.roses.kernel.cache.redis.AbstractRedisCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.dict.api.pojo.DictDetail;
|
|
@ -66,7 +66,6 @@ public interface DictService extends IService<SysDict>, DictApi {
|
|||
*/
|
||||
void del(DictRequest dictRequest);
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除字典
|
||||
*
|
||||
|
@ -74,8 +73,7 @@ public interface DictService extends IService<SysDict>, DictApi {
|
|||
* @date 2023/07/04 10:29
|
||||
*/
|
||||
void batchDelete(DictRequest dictRequest);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 修改字典
|
||||
*
|
||||
|
|
|
@ -130,10 +130,12 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
@Override
|
||||
public void del(DictRequest dictRequest) {
|
||||
this.removeById(dictRequest.getDictId());
|
||||
|
||||
// 删除字典缓存
|
||||
this.dictInfoCache.remove(String.valueOf(dictRequest.getDictId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void edit(DictRequest dictRequest) {
|
||||
|
||||
// 校验字典重复
|
||||
|
@ -151,6 +153,9 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
sysDict.setDictNamePinyin(pinYinApi.parseEveryPinyinFirstLetter(sysDict.getDictName()));
|
||||
|
||||
this.updateById(sysDict);
|
||||
|
||||
// 删除字典名称缓存
|
||||
this.dictInfoCache.remove(String.valueOf(sysDict.getDictId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -176,8 +181,22 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
|
||||
@Override
|
||||
public void removeByDictTypeId(Long dictTypeId) {
|
||||
|
||||
// 查询字典类型下的所有字典
|
||||
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysDictLambdaQueryWrapper.eq(SysDict::getDictTypeId, dictTypeId);
|
||||
sysDictLambdaQueryWrapper.select(SysDict::getDictId);
|
||||
List<SysDict> list = this.list(sysDictLambdaQueryWrapper);
|
||||
if (ObjectUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除所有字典的缓存
|
||||
list.forEach(sysDict -> {
|
||||
this.dictInfoCache.remove(String.valueOf(sysDict.getDictId()));
|
||||
});
|
||||
|
||||
// 删除字典类型下的所有字典
|
||||
this.remove(sysDictLambdaQueryWrapper);
|
||||
}
|
||||
|
||||
|
@ -286,6 +305,9 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
@Override
|
||||
public void deleteByDictId(Long dictId) {
|
||||
this.removeById(dictId);
|
||||
|
||||
// 删除字典详情缓存
|
||||
this.dictInfoCache.remove(dictId.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -357,6 +379,9 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
|
||||
// 更新字典
|
||||
this.edit(dictRequest);
|
||||
|
||||
// 删除字典详情缓存
|
||||
this.dictInfoCache.remove(String.valueOf(dictRequest.getDictId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -537,6 +562,11 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
@Override
|
||||
public void batchDelete(DictRequest dictRequest) {
|
||||
this.removeBatchByIds(dictRequest.getDictIdList());
|
||||
|
||||
// 循环删除缓存
|
||||
for (Long dictId : dictRequest.getDictIdList()) {
|
||||
this.dictInfoCache.remove(dictId.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import cn.hutool.cache.CacheUtil;
|
|||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.dict.api.pojo.DictDetail;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.cache.DictInfoMemoryCache;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.cache.dictname.DictInfoMemoryCache;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
|
|
@ -27,7 +27,7 @@ package cn.stylefeng.roses.kernel.dict.starter;
|
|||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil;
|
||||
import cn.stylefeng.roses.kernel.dict.api.pojo.DictDetail;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.cache.DictInfoRedisCache;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.cache.dictname.DictInfoRedisCache;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
|
Loading…
Reference in New Issue