How to Set a Ttl for @Cacheable

Set TTL fot caching different data with one CacheManager in Spring Boot

I used multiple cache managers combined with cache resolver. I followed these tutorials.

https://www.baeldung.com/spring-multiple-cache-managers

https://www.baeldung.com/spring-boot-caffeine-cache

how to configure different ttl for each redis cache when using @cacheable in springboot2.0

If you need configure different expire time for cache when using @cacheable ,
you can configure different CacheManager with different ttl,and specify cacheManager when using cache in your service.

 @Cacheable(cacheManager = "expireOneHour", value = "onehour", key = "'_onehour_'+#key", sync = true)

How to set TTL on Hazelcast cache map with spring cacheble

There are two topologies in which you can use Hazelcast: Embedded and Client-Server. Your Java Spring configuration configures Hazelcast Client, however your hazelcast.yaml is dedicated for the Embedded mode.

Try to either use your hazelcast.yaml configuration in your Hazelcast server. Or configure your cache in the Hazelcast client, for example, like this:

@Bean
HazelcastInstance hazelcastInstance() {
HazelcastInstance instance = HazelcastClient.newHazelcastClient(clientConfig());
instance.getConfig().addMapConfig(new MapConfig("items").setTimeToLiveSeconds(120));
return instance;
}


Related Topics



Leave a reply



Submit