mirror of https://gitee.com/stylefeng/roses
【8.3.3】【dict】【cache】添加字典缓存
parent
39a8a0c439
commit
fb80b235ed
|
@ -25,11 +25,18 @@
|
|||
</dependency>
|
||||
|
||||
<!--缓存的依赖-->
|
||||
<!--字典缓存的使用-->
|
||||
<!--内存或者redis的缓存-->
|
||||
<dependency>
|
||||
<groupId>com.javaguns.roses</groupId>
|
||||
<artifactId>cache-api</artifactId>
|
||||
<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>
|
||||
|
||||
<!--资源api模块-->
|
||||
|
|
|
@ -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>
|
||||
* key是职位id,value是字典详情
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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>
|
||||
* key是职位id,value是字典详情
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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.
|
||||
*
|
||||
* Guns采用APACHE 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:";
|
||||
|
||||
}
|
|
@ -31,6 +31,20 @@
|
|||
<version>${roses.version}</version>
|
||||
</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>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* Guns采用APACHE 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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.
|
||||
*
|
||||
* Guns采用APACHE 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.stylefeng.roses.kernel.dict.starter.DictMemoryCacheAutoConfiguration,\
|
||||
cn.stylefeng.roses.kernel.dict.starter.DictRedisCacheAutoConfiguration
|
Loading…
Reference in New Issue