From 83b1f3a48013a67c8bf385f8360ac67216fabe2d Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Wed, 27 Jul 2022 15:38:51 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=907.2.4=E3=80=91=E3=80=90cache=E3=80=91?= =?UTF-8?q?=E6=9B=B4=E6=96=B0cache=E4=BD=BF=E7=94=A8=E7=9A=84=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GunsMemoryCacheAutoConfiguration.java | 2 +- .../GunsRedisCacheAutoConfiguration.java | 2 +- .../modular/service/impl/DictServiceImpl.java | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/kernel-d-cache/memory-cache-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/cache/memory/starter/GunsMemoryCacheAutoConfiguration.java b/kernel-d-cache/memory-cache-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/cache/memory/starter/GunsMemoryCacheAutoConfiguration.java index e6c23b96d..28a584a72 100644 --- a/kernel-d-cache/memory-cache-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/cache/memory/starter/GunsMemoryCacheAutoConfiguration.java +++ b/kernel-d-cache/memory-cache-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/cache/memory/starter/GunsMemoryCacheAutoConfiguration.java @@ -48,7 +48,7 @@ public class GunsMemoryCacheAutoConfiguration { * @date 2021/1/31 20:39 */ @Bean - public DefaultStringMemoryCacheOperator defaultStringMemoryCacheOperator() { + public DefaultStringMemoryCacheOperator defaultStringCacheOperator() { TimedCache stringTimedCache = CacheUtil.newTimedCache(CacheConstants.DEFAULT_CACHE_TIMEOUT); return new DefaultStringMemoryCacheOperator(stringTimedCache); } diff --git a/kernel-d-cache/redis-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/cache/redis/starter/GunsRedisCacheAutoConfiguration.java b/kernel-d-cache/redis-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/cache/redis/starter/GunsRedisCacheAutoConfiguration.java index bf89d3dcd..ecbe9f9f0 100644 --- a/kernel-d-cache/redis-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/cache/redis/starter/GunsRedisCacheAutoConfiguration.java +++ b/kernel-d-cache/redis-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/cache/redis/starter/GunsRedisCacheAutoConfiguration.java @@ -84,7 +84,7 @@ public class GunsRedisCacheAutoConfiguration { * @date 2021/1/31 20:39 */ @Bean - public DefaultStringRedisCacheOperator defaultStringRedisCacheOperator(RedisTemplate stringRedisTemplate) { + public DefaultStringRedisCacheOperator defaultStringCacheOperator(RedisTemplate stringRedisTemplate) { return new DefaultStringRedisCacheOperator(stringRedisTemplate); } diff --git a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/service/impl/DictServiceImpl.java b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/service/impl/DictServiceImpl.java index a1d43038a..9e94aa3dc 100644 --- a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/service/impl/DictServiceImpl.java +++ b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/service/impl/DictServiceImpl.java @@ -74,11 +74,10 @@ public class DictServiceImpl extends ServiceImpl implements @Resource private DictTypeService dictTypeService; + @Resource(name = "defaultStringCacheOperator") + private CacheOperatorApi defaultStringCacheOperator; - @Resource - private CacheOperatorApi defaultStringMemoryCacheOperator; - - private static String CACHE_PREFIX = "dict:"; + private static final String CACHE_PREFIX = "dict:"; @Override @Transactional(rollbackFor = Exception.class) @@ -103,7 +102,7 @@ public class DictServiceImpl extends ServiceImpl implements this.updateById(sysDict); // 清除缓存中的字典值 - defaultStringMemoryCacheOperator.remove(CACHE_PREFIX + sysDict.getDictTypeCode() + "|" + sysDict.getDictCode()); + defaultStringCacheOperator.remove(CACHE_PREFIX + sysDict.getDictTypeCode() + "|" + sysDict.getDictCode()); } @Override @@ -122,8 +121,9 @@ public class DictServiceImpl extends ServiceImpl implements sysDict.setDictNamePinyin(pinYinApi.parseEveryPinyinFirstLetter(sysDict.getDictName())); this.updateById(sysDict); + // 清除缓存中的字典值 - defaultStringMemoryCacheOperator.remove(CACHE_PREFIX + sysDict.getDictTypeCode() + "|" + sysDict.getDictCode()); + defaultStringCacheOperator.remove(CACHE_PREFIX + sysDict.getDictTypeCode() + "|" + sysDict.getDictCode()); } @Override @@ -169,8 +169,8 @@ public class DictServiceImpl extends ServiceImpl implements @Override public String getDictName(String dictTypeCode, String dictCode) { - String dictName = defaultStringMemoryCacheOperator.get(CACHE_PREFIX + dictTypeCode + "|" + dictCode); - if(StrUtil.isNotEmpty(dictName)){ + String dictName = defaultStringCacheOperator.get(CACHE_PREFIX + dictTypeCode + "|" + dictCode); + if (StrUtil.isNotEmpty(dictName)) { return dictName; } LambdaQueryWrapper sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>(); @@ -192,7 +192,7 @@ public class DictServiceImpl extends ServiceImpl implements } dictName = list.get(0).getDictName(); - defaultStringMemoryCacheOperator.put(CACHE_PREFIX + dictTypeCode + "|" + dictCode, dictName); + defaultStringCacheOperator.put(CACHE_PREFIX + dictTypeCode + "|" + dictCode, dictName); if (dictName != null) { return dictName; } else {