Commit 72d2dcc68f46e14a868838434b5bcf681beb55bc
1 parent
105f1a27
feat: 将 redisCache 的扫描策略设置成 scan
Showing
4 changed files
with
35 additions
and
5 deletions
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/config/YudaoTenantAutoConfiguration.java
| @@ -4,6 +4,7 @@ import cn.hutool.core.annotation.AnnotationUtil; | @@ -4,6 +4,7 @@ import cn.hutool.core.annotation.AnnotationUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; | 5 | import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; |
| 6 | import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; | 6 | import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; |
| 7 | +import cn.iocoder.yudao.framework.redis.config.YudaoCacheProperties; | ||
| 7 | import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnoreAspect; | 8 | import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnoreAspect; |
| 8 | import cn.iocoder.yudao.framework.tenant.core.db.TenantDatabaseInterceptor; | 9 | import cn.iocoder.yudao.framework.tenant.core.db.TenantDatabaseInterceptor; |
| 9 | import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; | 10 | import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; |
| @@ -27,6 +28,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties | @@ -27,6 +28,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
| 27 | import org.springframework.boot.web.servlet.FilterRegistrationBean; | 28 | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| 28 | import org.springframework.context.annotation.Bean; | 29 | import org.springframework.context.annotation.Bean; |
| 29 | import org.springframework.context.annotation.Primary; | 30 | import org.springframework.context.annotation.Primary; |
| 31 | +import org.springframework.data.redis.cache.BatchStrategies; | ||
| 30 | import org.springframework.data.redis.cache.RedisCacheConfiguration; | 32 | import org.springframework.data.redis.cache.RedisCacheConfiguration; |
| 31 | import org.springframework.data.redis.cache.RedisCacheManager; | 33 | import org.springframework.data.redis.cache.RedisCacheManager; |
| 32 | import org.springframework.data.redis.cache.RedisCacheWriter; | 34 | import org.springframework.data.redis.cache.RedisCacheWriter; |
| @@ -124,10 +126,12 @@ public class YudaoTenantAutoConfiguration { | @@ -124,10 +126,12 @@ public class YudaoTenantAutoConfiguration { | ||
| 124 | @Bean | 126 | @Bean |
| 125 | @Primary // 引入租户时,tenantRedisCacheManager 为主 Bean | 127 | @Primary // 引入租户时,tenantRedisCacheManager 为主 Bean |
| 126 | public RedisCacheManager tenantRedisCacheManager(RedisTemplate<String, Object> redisTemplate, | 128 | public RedisCacheManager tenantRedisCacheManager(RedisTemplate<String, Object> redisTemplate, |
| 127 | - RedisCacheConfiguration redisCacheConfiguration) { | 129 | + RedisCacheConfiguration redisCacheConfiguration, |
| 130 | + YudaoCacheProperties yudaoCacheProperties) { | ||
| 128 | // 创建 RedisCacheWriter 对象 | 131 | // 创建 RedisCacheWriter 对象 |
| 129 | RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory()); | 132 | RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory()); |
| 130 | - RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory); | 133 | + RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory, |
| 134 | + BatchStrategies.scan(yudaoCacheProperties.getRedisScanBatchSize())); | ||
| 131 | // 创建 TenantRedisCacheManager 对象 | 135 | // 创建 TenantRedisCacheManager 对象 |
| 132 | return new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration); | 136 | return new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration); |
| 133 | } | 137 | } |
yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java
| @@ -8,6 +8,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties | @@ -8,6 +8,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
| 8 | import org.springframework.cache.annotation.EnableCaching; | 8 | import org.springframework.cache.annotation.EnableCaching; |
| 9 | import org.springframework.context.annotation.Bean; | 9 | import org.springframework.context.annotation.Bean; |
| 10 | import org.springframework.context.annotation.Primary; | 10 | import org.springframework.context.annotation.Primary; |
| 11 | +import org.springframework.data.redis.cache.BatchStrategies; | ||
| 11 | import org.springframework.data.redis.cache.RedisCacheConfiguration; | 12 | import org.springframework.data.redis.cache.RedisCacheConfiguration; |
| 12 | import org.springframework.data.redis.cache.RedisCacheManager; | 13 | import org.springframework.data.redis.cache.RedisCacheManager; |
| 13 | import org.springframework.data.redis.cache.RedisCacheWriter; | 14 | import org.springframework.data.redis.cache.RedisCacheWriter; |
| @@ -23,7 +24,7 @@ import static cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguratio | @@ -23,7 +24,7 @@ import static cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguratio | ||
| 23 | * Cache 配置类,基于 Redis 实现 | 24 | * Cache 配置类,基于 Redis 实现 |
| 24 | */ | 25 | */ |
| 25 | @AutoConfiguration | 26 | @AutoConfiguration |
| 26 | -@EnableConfigurationProperties({CacheProperties.class}) | 27 | +@EnableConfigurationProperties({CacheProperties.class, YudaoCacheProperties.class}) |
| 27 | @EnableCaching | 28 | @EnableCaching |
| 28 | public class YudaoCacheAutoConfiguration { | 29 | public class YudaoCacheAutoConfiguration { |
| 29 | 30 | ||
| @@ -62,10 +63,12 @@ public class YudaoCacheAutoConfiguration { | @@ -62,10 +63,12 @@ public class YudaoCacheAutoConfiguration { | ||
| 62 | 63 | ||
| 63 | @Bean | 64 | @Bean |
| 64 | public RedisCacheManager redisCacheManager(RedisTemplate<String, Object> redisTemplate, | 65 | public RedisCacheManager redisCacheManager(RedisTemplate<String, Object> redisTemplate, |
| 65 | - RedisCacheConfiguration redisCacheConfiguration) { | 66 | + RedisCacheConfiguration redisCacheConfiguration, |
| 67 | + YudaoCacheProperties yudaoCacheProperties) { | ||
| 66 | // 创建 RedisCacheWriter 对象 | 68 | // 创建 RedisCacheWriter 对象 |
| 67 | RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory()); | 69 | RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory()); |
| 68 | - RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory); | 70 | + RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory, |
| 71 | + BatchStrategies.scan(yudaoCacheProperties.getRedisScanBatchSize())); | ||
| 69 | // 创建 TenantRedisCacheManager 对象 | 72 | // 创建 TenantRedisCacheManager 对象 |
| 70 | return new TimeoutRedisCacheManager(cacheWriter, redisCacheConfiguration); | 73 | return new TimeoutRedisCacheManager(cacheWriter, redisCacheConfiguration); |
| 71 | } | 74 | } |
yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheProperties.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.redis.config; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 5 | +import org.springframework.validation.annotation.Validated; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * Cache 配置项 | ||
| 9 | + * | ||
| 10 | + * @author | ||
| 11 | + */ | ||
| 12 | +@ConfigurationProperties("yudao.cache") | ||
| 13 | +@Data | ||
| 14 | +@Validated | ||
| 15 | +public class YudaoCacheProperties { | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * redis scan 一次返回数量 | ||
| 19 | + */ | ||
| 20 | + private Integer redisScanBatchSize = 30; | ||
| 21 | +} |
yudao-server/src/main/resources/application.yaml
| @@ -204,6 +204,8 @@ yudao: | @@ -204,6 +204,8 @@ yudao: | ||
| 204 | order: | 204 | order: |
| 205 | app-id: 1 # 商户编号 | 205 | app-id: 1 # 商户编号 |
| 206 | expire-time: 2h # 支付的过期时间 | 206 | expire-time: 2h # 支付的过期时间 |
| 207 | + cache: # spring cache 相关配置 | ||
| 208 | + redis-scan-batch-size: 30 # redis scan 一次返回数量 | ||
| 207 | 209 | ||
| 208 | debug: false | 210 | debug: false |
| 209 | 211 |