diff --git a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/cache/dictnamemixed/MixedDictNameMemoryCache.java b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/cache/dictnamemixed/MixedDictNameMemoryCache.java new file mode 100644 index 000000000..384c7f2ae --- /dev/null +++ b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/cache/dictnamemixed/MixedDictNameMemoryCache.java @@ -0,0 +1,28 @@ +package cn.stylefeng.roses.kernel.dict.modular.cache.dictnamemixed; + +import cn.hutool.cache.impl.TimedCache; +import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator; +import cn.stylefeng.roses.kernel.dict.modular.constants.DictCacheConstants; + +/** + * 字典名称的缓存 + *

+ * key是混合类型的,value是字典名称 + *

+ * key可能有两种,1. 字典类型id+字典编码 2. 字典类型编码+字典编码 + * + * @author fengshuonan + * @since 2025/1/10 16:33 + */ +public class MixedDictNameMemoryCache extends AbstractMemoryCacheOperator { + + public MixedDictNameMemoryCache(TimedCache timedCache) { + super(timedCache); + } + + @Override + public String getCommonKeyPrefix() { + return DictCacheConstants.DICT_MIXED_NAME_CACHE_PREFIX; + } + +} \ No newline at end of file diff --git a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/cache/dictnamemixed/MixedDictNameRedisCache.java b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/cache/dictnamemixed/MixedDictNameRedisCache.java new file mode 100644 index 000000000..de60c4a1b --- /dev/null +++ b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/cache/dictnamemixed/MixedDictNameRedisCache.java @@ -0,0 +1,28 @@ +package cn.stylefeng.roses.kernel.dict.modular.cache.dictnamemixed; + +import cn.stylefeng.roses.kernel.cache.redis.AbstractRedisCacheOperator; +import cn.stylefeng.roses.kernel.dict.modular.constants.DictCacheConstants; +import org.springframework.data.redis.core.RedisTemplate; + +/** + * 字典名称的缓存 + *

+ * key是混合类型的,value是字典名称 + *

+ * key可能有两种,1. 字典类型id+字典编码 2. 字典类型编码+字典编码 + * + * @author fengshuonan + * @since 2025/1/10 14:10 + */ +public class MixedDictNameRedisCache extends AbstractRedisCacheOperator { + + public MixedDictNameRedisCache(RedisTemplate redisTemplate) { + super(redisTemplate); + } + + @Override + public String getCommonKeyPrefix() { + return DictCacheConstants.DICT_MIXED_NAME_CACHE_PREFIX; + } + +} diff --git a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/constants/DictCacheConstants.java b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/constants/DictCacheConstants.java index cd3dbc22f..40b173b25 100644 --- a/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/constants/DictCacheConstants.java +++ b/kernel-s-dict/dict-business/src/main/java/cn/stylefeng/roses/kernel/dict/modular/constants/DictCacheConstants.java @@ -37,4 +37,13 @@ public interface DictCacheConstants { */ String DICT_INFO_CACHE_PREFIX = "DICT:INFO:"; + /** + * 字典名称的缓存 + *

+ * key是混合类型的,value是字典名称 + *

+ * key可能有两种,1. 字典类型id+字典编码 2. 字典类型编码+字典编码 + */ + String DICT_MIXED_NAME_CACHE_PREFIX = "DICT:MIXED:"; + } diff --git a/kernel-s-dict/dict-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/dict/starter/DictMemoryCacheAutoConfiguration.java b/kernel-s-dict/dict-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/dict/starter/DictMemoryCacheAutoConfiguration.java index 8cd646d8e..4eb21ab9a 100644 --- a/kernel-s-dict/dict-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/dict/starter/DictMemoryCacheAutoConfiguration.java +++ b/kernel-s-dict/dict-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/dict/starter/DictMemoryCacheAutoConfiguration.java @@ -29,6 +29,7 @@ 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.dictname.DictInfoMemoryCache; +import cn.stylefeng.roses.kernel.dict.modular.cache.dictnamemixed.MixedDictNameMemoryCache; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -55,4 +56,20 @@ public class DictMemoryCacheAutoConfiguration { return new DictInfoMemoryCache(themeCache); } + /** + * 字典名称的缓存,混合类型的key + *

+ * key是混合类型的,value是字典名称 + *

+ * key可能有两种,1. 字典类型id+字典编码 2. 字典类型编码+字典编码 + * + * @author fengshuonan + * @since 2025/1/10 16:35 + */ + @Bean + public CacheOperatorApi dictNameMixedCache() { + TimedCache themeCache = CacheUtil.newTimedCache(1000 * 3600L); + return new MixedDictNameMemoryCache(themeCache); + } + } diff --git a/kernel-s-dict/dict-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/dict/starter/DictRedisCacheAutoConfiguration.java b/kernel-s-dict/dict-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/dict/starter/DictRedisCacheAutoConfiguration.java index b79a9cb88..2903ccf67 100644 --- a/kernel-s-dict/dict-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/dict/starter/DictRedisCacheAutoConfiguration.java +++ b/kernel-s-dict/dict-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/dict/starter/DictRedisCacheAutoConfiguration.java @@ -28,6 +28,7 @@ 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.dictname.DictInfoRedisCache; +import cn.stylefeng.roses.kernel.dict.modular.cache.dictnamemixed.MixedDictNameRedisCache; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -56,4 +57,20 @@ public class DictRedisCacheAutoConfiguration { return new DictInfoRedisCache(redisTemplate); } + /** + * 字典的Redis缓存 + *

+ * key是混合类型的,value是字典名称 + *

+ * key可能有两种,1. 字典类型id+字典编码 2. 字典类型编码+字典编码 + * + * @author fengshuonan + * @since 2025/1/10 15:05 + */ + @Bean + public CacheOperatorApi dictNameMixedCache(RedisConnectionFactory redisConnectionFactory) { + RedisTemplate redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory); + return new MixedDictNameRedisCache(redisTemplate); + } + }