【7.2.4】【cache】更新cache使用的名称

pull/34/head
fengshuonan 2022-07-27 15:38:51 +08:00
parent 438e573a89
commit 83b1f3a480
3 changed files with 11 additions and 11 deletions

View File

@ -48,7 +48,7 @@ public class GunsMemoryCacheAutoConfiguration {
* @date 2021/1/31 20:39 * @date 2021/1/31 20:39
*/ */
@Bean @Bean
public DefaultStringMemoryCacheOperator defaultStringMemoryCacheOperator() { public DefaultStringMemoryCacheOperator defaultStringCacheOperator() {
TimedCache<String, String> stringTimedCache = CacheUtil.newTimedCache(CacheConstants.DEFAULT_CACHE_TIMEOUT); TimedCache<String, String> stringTimedCache = CacheUtil.newTimedCache(CacheConstants.DEFAULT_CACHE_TIMEOUT);
return new DefaultStringMemoryCacheOperator(stringTimedCache); return new DefaultStringMemoryCacheOperator(stringTimedCache);
} }

View File

@ -84,7 +84,7 @@ public class GunsRedisCacheAutoConfiguration {
* @date 2021/1/31 20:39 * @date 2021/1/31 20:39
*/ */
@Bean @Bean
public DefaultStringRedisCacheOperator defaultStringRedisCacheOperator(RedisTemplate<String, String> stringRedisTemplate) { public DefaultStringRedisCacheOperator defaultStringCacheOperator(RedisTemplate<String, String> stringRedisTemplate) {
return new DefaultStringRedisCacheOperator(stringRedisTemplate); return new DefaultStringRedisCacheOperator(stringRedisTemplate);
} }

View File

@ -74,11 +74,10 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
@Resource @Resource
private DictTypeService dictTypeService; private DictTypeService dictTypeService;
@Resource(name = "defaultStringCacheOperator")
private CacheOperatorApi<String> defaultStringCacheOperator;
@Resource private static final String CACHE_PREFIX = "dict:";
private CacheOperatorApi<String> defaultStringMemoryCacheOperator;
private static String CACHE_PREFIX = "dict:";
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -103,7 +102,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
this.updateById(sysDict); this.updateById(sysDict);
// 清除缓存中的字典值 // 清除缓存中的字典值
defaultStringMemoryCacheOperator.remove(CACHE_PREFIX + sysDict.getDictTypeCode() + "|" + sysDict.getDictCode()); defaultStringCacheOperator.remove(CACHE_PREFIX + sysDict.getDictTypeCode() + "|" + sysDict.getDictCode());
} }
@Override @Override
@ -122,8 +121,9 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
sysDict.setDictNamePinyin(pinYinApi.parseEveryPinyinFirstLetter(sysDict.getDictName())); sysDict.setDictNamePinyin(pinYinApi.parseEveryPinyinFirstLetter(sysDict.getDictName()));
this.updateById(sysDict); this.updateById(sysDict);
// 清除缓存中的字典值 // 清除缓存中的字典值
defaultStringMemoryCacheOperator.remove(CACHE_PREFIX + sysDict.getDictTypeCode() + "|" + sysDict.getDictCode()); defaultStringCacheOperator.remove(CACHE_PREFIX + sysDict.getDictTypeCode() + "|" + sysDict.getDictCode());
} }
@Override @Override
@ -169,8 +169,8 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
@Override @Override
public String getDictName(String dictTypeCode, String dictCode) { public String getDictName(String dictTypeCode, String dictCode) {
String dictName = defaultStringMemoryCacheOperator.get(CACHE_PREFIX + dictTypeCode + "|" + dictCode); String dictName = defaultStringCacheOperator.get(CACHE_PREFIX + dictTypeCode + "|" + dictCode);
if(StrUtil.isNotEmpty(dictName)){ if (StrUtil.isNotEmpty(dictName)) {
return dictName; return dictName;
} }
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
@ -192,7 +192,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
} }
dictName = list.get(0).getDictName(); dictName = list.get(0).getDictName();
defaultStringMemoryCacheOperator.put(CACHE_PREFIX + dictTypeCode + "|" + dictCode, dictName); defaultStringCacheOperator.put(CACHE_PREFIX + dictTypeCode + "|" + dictCode, dictName);
if (dictName != null) { if (dictName != null) {
return dictName; return dictName;
} else { } else {