0

我想在 5 分钟后让我的 hazelcast 地图为空,以便我可以将更新的 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;

}
4

1 回答 1

0

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

于 2017-01-05T07:18:45.170 回答