mirror of https://github.com/jeecgboot/jeecg-boot
redis增加名字空间分开过期时间 #269
parent
7621cad118
commit
0b2a98d6f1
|
@ -25,6 +25,8 @@ import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping;
|
||||
|
||||
import static java.util.Collections.singletonMap;
|
||||
|
||||
@Configuration
|
||||
@EnableCaching // 开启缓存支持
|
||||
public class RedisConfig extends CachingConfigurerSupport {
|
||||
|
@ -83,8 +85,12 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||
// 以锁写入的方式创建RedisCacheWriter对象
|
||||
RedisCacheWriter writer = RedisCacheWriter.lockingRedisCacheWriter(factory);
|
||||
// 创建默认缓存配置对象
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(3)); //设置缓存默认有效期3小时;
|
||||
RedisCacheManager cacheManager = new RedisCacheManager(writer, config);
|
||||
/* 默认配置,设置缓存有效期 1小时*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue