I'm upgrading a project which uses Spring Data Redis to 2.x. Previously, the cache manager could be configured with a default expiration using RedisCacheManager.setDefaultExpiration(defaultExpireTime). This option does not seem to exist in 2.x. What is the equivalent in 2.x? Is it RedisCacheConfiguration.entryTtl(ttl), or something else?
I'm probably missing something, but I'm not finding a migration guide to Spring Data Redis 2.x. Does such a migration guide exist?
In short, I would like to migrate the following code to Redis 2.x:
public CacheManager cacheManager() {
RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate());
redisCacheManager.setDefaultExpiration(DEFAULT_EXPIRATION_SECONDS);
return redisCacheManager;
}
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory());
return template;
}
Is the following equivalent? If not, what would be the equivalent code in Redis 2.x?
public CacheManager cacheManager() {
return RedisCacheManager.builder(redisConnectionFactory())
.cacheDefaults(RedisCacheConfiguration.defaultCacheConfig().entryTtl(DEFAULT_EXPIRATION_DURATION))
.build();
}