提交 0b2a98d6 编写于 作者: JEECG低代码平台's avatar JEECG低代码平台

redis增加名字空间分开过期时间 #269

上级 7621cad1
...@@ -25,6 +25,8 @@ import com.fasterxml.jackson.annotation.PropertyAccessor; ...@@ -25,6 +25,8 @@ import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping; import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping;
import static java.util.Collections.singletonMap;
@Configuration @Configuration
@EnableCaching // 开启缓存支持 @EnableCaching // 开启缓存支持
public class RedisConfig extends CachingConfigurerSupport { public class RedisConfig extends CachingConfigurerSupport {
...@@ -83,8 +85,12 @@ public class RedisConfig extends CachingConfigurerSupport { ...@@ -83,8 +85,12 @@ public class RedisConfig extends CachingConfigurerSupport {
// 以锁写入的方式创建RedisCacheWriter对象 // 以锁写入的方式创建RedisCacheWriter对象
RedisCacheWriter writer = RedisCacheWriter.lockingRedisCacheWriter(factory); RedisCacheWriter writer = RedisCacheWriter.lockingRedisCacheWriter(factory);
// 创建默认缓存配置对象 // 创建默认缓存配置对象
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(3)); //设置缓存默认有效期3小时; /* 默认配置,设置缓存有效期 1小时*/
RedisCacheManager cacheManager = new RedisCacheManager(writer, config); RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(1)).disableCachingNullValues();
/* 配置test的超时时间为120s*/
RedisCacheManager cacheManager = RedisCacheManager.builder(RedisCacheWriter.lockingRedisCacheWriter(lettuceConnectionFactory)).cacheDefaults(defaultCacheConfig)
.withInitialCacheConfigurations(singletonMap("test", RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(120)).disableCachingNullValues()))
.transactionAware().build();
return cacheManager; return cacheManager;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册