【8.3.3】【dict】【cache】添加字典缓存

pull/62/head
stylefeng 2025-01-10 15:07:26 +08:00
parent 39a8a0c439
commit fb80b235ed
8 changed files with 237 additions and 2 deletions

View File

@ -25,11 +25,18 @@
</dependency> </dependency>
<!--缓存的依赖--> <!--缓存的依赖-->
<!--字典缓存的使用--> <!--内存或者redis的缓存-->
<dependency> <dependency>
<groupId>com.javaguns.roses</groupId> <groupId>com.javaguns.roses</groupId>
<artifactId>cache-api</artifactId> <artifactId>cache-sdk-memory</artifactId>
<version>${roses.version}</version> <version>${roses.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.javaguns.roses</groupId>
<artifactId>cache-sdk-redis</artifactId>
<version>${roses.version}</version>
<optional>true</optional>
</dependency> </dependency>
<!--资源api模块--> <!--资源api模块-->

View File

@ -0,0 +1,27 @@
package cn.stylefeng.roses.kernel.dict.modular.cache;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
import cn.stylefeng.roses.kernel.dict.api.pojo.DictDetail;
import cn.stylefeng.roses.kernel.dict.modular.constants.DictCacheConstants;
/**
*
* <p>
* keyidvalue
*
* @author fengshuonan
* @since 2025/1/10 14:55
*/
public class DictInfoMemoryCache extends AbstractMemoryCacheOperator<DictDetail> {
public DictInfoMemoryCache(TimedCache<String, DictDetail> timedCache) {
super(timedCache);
}
@Override
public String getCommonKeyPrefix() {
return DictCacheConstants.DICT_INFO_CACHE_PREFIX;
}
}

View File

@ -0,0 +1,27 @@
package cn.stylefeng.roses.kernel.dict.modular.cache;
import cn.stylefeng.roses.kernel.cache.redis.AbstractRedisCacheOperator;
import cn.stylefeng.roses.kernel.dict.api.pojo.DictDetail;
import cn.stylefeng.roses.kernel.dict.modular.constants.DictCacheConstants;
import org.springframework.data.redis.core.RedisTemplate;
/**
*
* <p>
* keyidvalue
*
* @author fengshuonan
* @since 2025/1/10 14:10
*/
public class DictInfoRedisCache extends AbstractRedisCacheOperator<DictDetail> {
public DictInfoRedisCache(RedisTemplate<String, DictDetail> redisTemplate) {
super(redisTemplate);
}
@Override
public String getCommonKeyPrefix() {
return DictCacheConstants.DICT_INFO_CACHE_PREFIX;
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.dict.modular.constants;
/**
*
*
* @author fengshuonan
* @since 2025/1/10 14:50
*/
public interface DictCacheConstants {
/**
*
*/
String DICT_INFO_CACHE_PREFIX = "DICT:INFO:";
}

View File

@ -31,6 +31,20 @@
<version>${roses.version}</version> <version>${roses.version}</version>
</dependency> </dependency>
<!--缓存配置-->
<dependency>
<groupId>com.javaguns.roses</groupId>
<artifactId>cache-sdk-memory</artifactId>
<version>${roses.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.javaguns.roses</groupId>
<artifactId>cache-sdk-redis</artifactId>
<version>${roses.version}</version>
<optional>true</optional>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,58 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.dict.starter;
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 org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
*
* @author fengshuonan
* @since 2025/1/10 15:03
*/
@Configuration
@ConditionalOnMissingClass("org.springframework.data.redis.connection.RedisConnectionFactory")
public class DictMemoryCacheAutoConfiguration {
/**
*
*
* @author fengshuonan
* @since 2025/1/10 15:03
*/
@Bean
public CacheOperatorApi<DictDetail> dictInfoCache() {
TimedCache<String, DictDetail> themeCache = CacheUtil.newTimedCache(1000 * 3600L);
return new DictInfoMemoryCache(themeCache);
}
}

View File

@ -0,0 +1,59 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
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 org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
/**
* Redis
*
* @author fengshuonan
* @since 2025/1/10 15:03
*/
@Configuration
@ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory")
public class DictRedisCacheAutoConfiguration {
/**
* Redis
*
* @author fengshuonan
* @since 2025/1/10 15:05
*/
@Bean
public CacheOperatorApi<DictDetail> dictInfoCache(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, DictDetail> redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory);
return new DictInfoRedisCache(redisTemplate);
}
}

View File

@ -0,0 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.stylefeng.roses.kernel.dict.starter.DictMemoryCacheAutoConfiguration,\
cn.stylefeng.roses.kernel.dict.starter.DictRedisCacheAutoConfiguration