更新された Db レコードを配置できるように、5 分後に hazelcast マップを空にしたいと考えています。しかし、null にはならず、古いレコードがまだ含まれています。以下は、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;
}