Hazelcast缓存不会变空以存储更新的记录

时间:2016-12-30 06:15:14

标签: java caching hazelcast hazelcast-imap

我希望在5分钟后让我的淡褐色地图变空,这样我就可以在其中放入更新的Db记录。但是它没有变为空并且仍然包含旧记录。下面是我在hazelcast缓存服务器中的hazlecast.xml文件。

<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>

我的Java代码如下:

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);
        }

诽谤宣言:

   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();
}

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 个答案:

答案 0 :(得分:0)

你尝试过hazelMap.get(key); 5分钟后?

相关问题