Hazelcast cache not getting empty to store updated records

952 views Asked by At

I want to make my hazelcast map empty after 5 minutes so that i can put updated Db records in it. But its not getting null and still contains old records.Below is my hazlecast.xml file in hazelcast cache server.

<map name="CdnConfig">
  <in-memory-format>BINARY</in-memory-format>
  <backup-count>0</backup-count>
  <async-backup-count>0</async-backup-count>
  <time-to-live-seconds>300</time-to-live-seconds>
  <max-idle-seconds>0</max-idle-seconds>
  <eviction-policy>LRU</eviction-policy>
  <max-size policy="PER_NODE">1000</max-size>
  <eviction-percentage>25</eviction-percentage>
  <min-eviction-check-millis>5000</min-eviction-check-millis>
</map>

My Java code is like:

List<CdnConfigDto> dataList=(List<CdnConfigDto>)hazelCastCache.getDataFromCache("CdnConfig", key);
   if (dataList != null) {
        LOGGER.info("HazelcastCache conatains records ");
 } else {
       LOGGER.info("HazelcastCache does not contains records ");
       dataList = configurationService.getDataFromDB();
       hazelCastCache.addDataToCache("CdnConfig", key, dataList);
        }

Declaration of hazelcast:

   private static HazelcastInstance hazelcastInstance;
   private static HazelCastCache instance = null;
   public static HazelCastCache getInstance() {
    return instance;
}

 public static void initCache() {
    if (instance == null) {
        synchronized (HazelCastCache.class) {
            if (instance == null) {
                instance = new HazelCastCache();
            }
        }
    }
}

private HazelCastCache() {
    hazelcastInstance = HazelcastCacheInstance.getHazelcastInstance();
}

Method implementation of getDataFromCache():--

 public Object getDataFromCache(String mapName, Object key) {
    Object data = null;
    IMap<Object, Object> hazelMap = hazelcastInstance.getMap(mapName);
    if (null != hazelMap) {
        data = hazelMap.get(key);
    }

    return data;

}
1

There are 1 answers

0
ihsan demir On

Did you try hazelMap.get(key); after 5 minutes?