Commit 134e5ca20fb167d489bb53b7d5942fa89fc466bd
1 parent
64c8dd62
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 | 4 | import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; |
| 6 | 6 | import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; |
| 7 | +import cn.iocoder.yudao.framework.redis.config.YudaoCacheProperties; | |
| 7 | 8 | import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnoreAspect; |
| 8 | 9 | import cn.iocoder.yudao.framework.tenant.core.db.TenantDatabaseInterceptor; |
| 9 | 10 | import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; |
| ... | ... | @@ -27,6 +28,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties |
| 27 | 28 | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| 28 | 29 | import org.springframework.context.annotation.Bean; |
| 29 | 30 | import org.springframework.context.annotation.Primary; |
| 31 | +import org.springframework.data.redis.cache.BatchStrategies; | |
| 30 | 32 | import org.springframework.data.redis.cache.RedisCacheConfiguration; |
| 31 | 33 | import org.springframework.data.redis.cache.RedisCacheManager; |
| 32 | 34 | import org.springframework.data.redis.cache.RedisCacheWriter; |
| ... | ... | @@ -124,10 +126,12 @@ public class YudaoTenantAutoConfiguration { |
| 124 | 126 | @Bean |
| 125 | 127 | @Primary // 引入租户时,tenantRedisCacheManager 为主 Bean |
| 126 | 128 | public RedisCacheManager tenantRedisCacheManager(RedisTemplate<String, Object> redisTemplate, |
| 127 | - RedisCacheConfiguration redisCacheConfiguration) { | |
| 129 | + RedisCacheConfiguration redisCacheConfiguration, | |
| 130 | + YudaoCacheProperties yudaoCacheProperties) { | |
| 128 | 131 | // 创建 RedisCacheWriter 对象 |
| 129 | 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 | 135 | // 创建 TenantRedisCacheManager 对象 |
| 132 | 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 | 8 | import org.springframework.cache.annotation.EnableCaching; |
| 9 | 9 | import org.springframework.context.annotation.Bean; |
| 10 | 10 | import org.springframework.context.annotation.Primary; |
| 11 | +import org.springframework.data.redis.cache.BatchStrategies; | |
| 11 | 12 | import org.springframework.data.redis.cache.RedisCacheConfiguration; |
| 12 | 13 | import org.springframework.data.redis.cache.RedisCacheManager; |
| 13 | 14 | import org.springframework.data.redis.cache.RedisCacheWriter; |
| ... | ... | @@ -23,7 +24,7 @@ import static cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguratio |
| 23 | 24 | * Cache 配置类,基于 Redis 实现 |
| 24 | 25 | */ |
| 25 | 26 | @AutoConfiguration |
| 26 | -@EnableConfigurationProperties({CacheProperties.class}) | |
| 27 | +@EnableConfigurationProperties({CacheProperties.class, YudaoCacheProperties.class}) | |
| 27 | 28 | @EnableCaching |
| 28 | 29 | public class YudaoCacheAutoConfiguration { |
| 29 | 30 | |
| ... | ... | @@ -62,10 +63,12 @@ public class YudaoCacheAutoConfiguration { |
| 62 | 63 | |
| 63 | 64 | @Bean |
| 64 | 65 | public RedisCacheManager redisCacheManager(RedisTemplate<String, Object> redisTemplate, |
| 65 | - RedisCacheConfiguration redisCacheConfiguration) { | |
| 66 | + RedisCacheConfiguration redisCacheConfiguration, | |
| 67 | + YudaoCacheProperties yudaoCacheProperties) { | |
| 66 | 68 | // 创建 RedisCacheWriter 对象 |
| 67 | 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 | 72 | // 创建 TenantRedisCacheManager 对象 |
| 70 | 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