I am using Hazelcast cluster cache with spring boot. I am using the 4.2 version of hazelcast.
Caching is working fine but it doesn't evict the data from the cache map after TTL. Always keeping the same data. I tried a lot of ways of setting ttl but didn't get any success.
Here is my chance config class
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.spring.cache.HazelcastCacheManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableCaching
public class CacheConfig {
@Value("${hazelcast.cluster-name}")
private String hzClusterName;
@Value("${hazelcast.address}")
private String hzAddress;
@Bean
HazelcastInstance hazelcastInstance() {
return HazelcastClient.newHazelcastClient(clientConfig());
}
@Bean
public ClientConfig clientConfig() {
ClientConfig cfg = ClientConfig.load();
cfg.setClusterName(hzClusterName);
cfg.getNetworkConfig().addAddress(hzAddress);
return cfg;
}
@Bean
public CacheManager cacheManager() {
return new HazelcastCacheManager(hazelcastInstance());
}
}
The cache class where I am using cacheable
@Cacheable("items")
public String getInfo(String systemSkuRef) {
logger.debug("Not using cache, fetch and put in cache");
return "Item Info";
}
I tried by using hazelcast.yaml file in src/main/resources by setting
hazelcast:
network:
public-address:
cluster-name: dev
map:
items:
time-to-live-seconds: 120
max-idle-seconds: 60
eviction:
eviction-policy: LRU
max-size-policy: PER_NODE
size: 1000
is there any other way or how can I achieve this, Thanks for your help