Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Set TTL for Redis cache to specific time

$
0
0

I am using RedisCacheManager using spring boot. I want to expire the cache at 23:59:59 everyday i.e end of the day. How can I do that? I can see that it can be done only relatively by using Duration.ofHours(3) Or Duration.ofMinutes(3) etc. But in my case, I want to set the ttl to a specific time, so that the cache expires every day at 23:59:59. Below is the code snippet I am using :

    public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {        Duration expiration = Duration.ofHours(3);        RedisCacheManager redisCacheManager =                RedisCacheManager.builder(redisConnectionFactory)                        .cacheDefaults(                                RedisCacheConfiguration.defaultCacheConfig()                                        .serializeValuesWith(                                                RedisSerializationContext.SerializationPair.fromSerializer(                                                        new GenericJackson2JsonRedisSerializer()))                                        .entryTtl(expiration))                        .build();        redisCacheManager.setTransactionAware(false);        return redisCacheManager;    }

Please suggest.


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>