mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 17:21:53 +08:00
feat: 将 redisCache 的扫描策略设置成 scan
This commit is contained in:
parent
105f1a2707
commit
72d2dcc68f
@ -4,6 +4,7 @@ import cn.hutool.core.annotation.AnnotationUtil;
|
|||||||
import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
|
import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
|
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
|
||||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||||
|
import cn.iocoder.yudao.framework.redis.config.YudaoCacheProperties;
|
||||||
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnoreAspect;
|
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnoreAspect;
|
||||||
import cn.iocoder.yudao.framework.tenant.core.db.TenantDatabaseInterceptor;
|
import cn.iocoder.yudao.framework.tenant.core.db.TenantDatabaseInterceptor;
|
||||||
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
|
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
|
||||||
@ -27,6 +28,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.data.redis.cache.BatchStrategies;
|
||||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||||
import org.springframework.data.redis.cache.RedisCacheWriter;
|
import org.springframework.data.redis.cache.RedisCacheWriter;
|
||||||
@ -124,10 +126,12 @@ public class YudaoTenantAutoConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
@Primary // 引入租户时,tenantRedisCacheManager 为主 Bean
|
@Primary // 引入租户时,tenantRedisCacheManager 为主 Bean
|
||||||
public RedisCacheManager tenantRedisCacheManager(RedisTemplate<String, Object> redisTemplate,
|
public RedisCacheManager tenantRedisCacheManager(RedisTemplate<String, Object> redisTemplate,
|
||||||
RedisCacheConfiguration redisCacheConfiguration) {
|
RedisCacheConfiguration redisCacheConfiguration,
|
||||||
|
YudaoCacheProperties yudaoCacheProperties) {
|
||||||
// 创建 RedisCacheWriter 对象
|
// 创建 RedisCacheWriter 对象
|
||||||
RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory());
|
RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory());
|
||||||
RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
|
RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory,
|
||||||
|
BatchStrategies.scan(yudaoCacheProperties.getRedisScanBatchSize()));
|
||||||
// 创建 TenantRedisCacheManager 对象
|
// 创建 TenantRedisCacheManager 对象
|
||||||
return new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration);
|
return new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|||||||
import org.springframework.cache.annotation.EnableCaching;
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.data.redis.cache.BatchStrategies;
|
||||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||||
import org.springframework.data.redis.cache.RedisCacheWriter;
|
import org.springframework.data.redis.cache.RedisCacheWriter;
|
||||||
@ -23,7 +24,7 @@ import static cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguratio
|
|||||||
* Cache 配置类,基于 Redis 实现
|
* Cache 配置类,基于 Redis 实现
|
||||||
*/
|
*/
|
||||||
@AutoConfiguration
|
@AutoConfiguration
|
||||||
@EnableConfigurationProperties({CacheProperties.class})
|
@EnableConfigurationProperties({CacheProperties.class, YudaoCacheProperties.class})
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
public class YudaoCacheAutoConfiguration {
|
public class YudaoCacheAutoConfiguration {
|
||||||
|
|
||||||
@ -62,10 +63,12 @@ public class YudaoCacheAutoConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RedisCacheManager redisCacheManager(RedisTemplate<String, Object> redisTemplate,
|
public RedisCacheManager redisCacheManager(RedisTemplate<String, Object> redisTemplate,
|
||||||
RedisCacheConfiguration redisCacheConfiguration) {
|
RedisCacheConfiguration redisCacheConfiguration,
|
||||||
|
YudaoCacheProperties yudaoCacheProperties) {
|
||||||
// 创建 RedisCacheWriter 对象
|
// 创建 RedisCacheWriter 对象
|
||||||
RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory());
|
RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory());
|
||||||
RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
|
RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory,
|
||||||
|
BatchStrategies.scan(yudaoCacheProperties.getRedisScanBatchSize()));
|
||||||
// 创建 TenantRedisCacheManager 对象
|
// 创建 TenantRedisCacheManager 对象
|
||||||
return new TimeoutRedisCacheManager(cacheWriter, redisCacheConfiguration);
|
return new TimeoutRedisCacheManager(cacheWriter, redisCacheConfiguration);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package cn.iocoder.yudao.framework.redis.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache 配置项
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties("yudao.cache")
|
||||||
|
@Data
|
||||||
|
@Validated
|
||||||
|
public class YudaoCacheProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redis scan 一次返回数量
|
||||||
|
*/
|
||||||
|
private Integer redisScanBatchSize = 30;
|
||||||
|
}
|
@ -204,6 +204,8 @@ yudao:
|
|||||||
order:
|
order:
|
||||||
app-id: 1 # 商户编号
|
app-id: 1 # 商户编号
|
||||||
expire-time: 2h # 支付的过期时间
|
expire-time: 2h # 支付的过期时间
|
||||||
|
cache: # spring cache 相关配置
|
||||||
|
redis-scan-batch-size: 30 # redis scan 一次返回数量
|
||||||
|
|
||||||
debug: false
|
debug: false
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user