Commit 78a2a2ecb7656237efcd059c1470545e70531bc7
1 parent
901fcaa7
redis增加名字空间分开过期时间 #269
Showing
1 changed file
with
8 additions
and
2 deletions
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/config/RedisConfig.java
@@ -25,6 +25,8 @@ import com.fasterxml.jackson.annotation.PropertyAccessor; | @@ -25,6 +25,8 @@ import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
25 | import com.fasterxml.jackson.databind.ObjectMapper; | 25 | import com.fasterxml.jackson.databind.ObjectMapper; |
26 | import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping; | 26 | import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping; |
27 | 27 | ||
28 | +import static java.util.Collections.singletonMap; | ||
29 | + | ||
28 | @Configuration | 30 | @Configuration |
29 | @EnableCaching // 开启缓存支持 | 31 | @EnableCaching // 开启缓存支持 |
30 | public class RedisConfig extends CachingConfigurerSupport { | 32 | public class RedisConfig extends CachingConfigurerSupport { |
@@ -83,8 +85,12 @@ public class RedisConfig extends CachingConfigurerSupport { | @@ -83,8 +85,12 @@ public class RedisConfig extends CachingConfigurerSupport { | ||
83 | // 以锁写入的方式创建RedisCacheWriter对象 | 85 | // 以锁写入的方式创建RedisCacheWriter对象 |
84 | RedisCacheWriter writer = RedisCacheWriter.lockingRedisCacheWriter(factory); | 86 | RedisCacheWriter writer = RedisCacheWriter.lockingRedisCacheWriter(factory); |
85 | // 创建默认缓存配置对象 | 87 | // 创建默认缓存配置对象 |
86 | - RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(3)); //设置缓存默认有效期3小时; | ||
87 | - RedisCacheManager cacheManager = new RedisCacheManager(writer, config); | 88 | + /* 默认配置,设置缓存有效期 1小时*/ |
89 | + RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(1)).disableCachingNullValues(); | ||
90 | + /* 配置test的超时时间为120s*/ | ||
91 | + RedisCacheManager cacheManager = RedisCacheManager.builder(RedisCacheWriter.lockingRedisCacheWriter(lettuceConnectionFactory)).cacheDefaults(defaultCacheConfig) | ||
92 | + .withInitialCacheConfigurations(singletonMap("test", RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(120)).disableCachingNullValues())) | ||
93 | + .transactionAware().build(); | ||
88 | return cacheManager; | 94 | return cacheManager; |
89 | } | 95 | } |
90 | 96 |