0
我想讓我的榛木地圖在5分鐘後變空,以便我可以將更新的Db記錄放入其中。但它沒有變爲空,仍然包含舊的記錄。以下是我在hazelcast緩存服務器中的hazlecast.xml文件。Hazelcast緩存沒有變空來存儲更新的記錄
<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;
}
'hazelcast.xml'或'hazlecast.xml'? – noctarius
你可以發佈'hazelCastCache'的聲明和'getDataFromCache'&'addDataToCache'的方法實現嗎? –
嗨!幸福的新的一年......事實上,我採取了另一條路線,而不是依賴於驅逐政策,每當有任何CRUD操作時,我都會進行緩存重置。但仍然想知道爲什麼上述方法不起作用。 @Desai:我已經在上面發佈了代碼.. @ noctarius:它的hazelcast.xml –