我想在5分钟后将我的Hazelcast映射清空,以便我可以将更新的DB记录放入其中。但是它没有零,仍然包含旧记录。BELOW是我的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);
}
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();
}
方法实现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;
}
您是否尝试过HazelMap.get(key);5分钟后?