0
업데이트 된 Db 레코드를 넣을 수 있도록 5 분 후에 내 hazelcast 맵을 비워야합니다. 하지만 null이 아니라 여전히 오래된 records.Below 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>
내 자바 코드 같은 것입니다 : hazelcast의
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);
}
선언 : getDataFromCache의
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();
}
방법의 구현() : -
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'의 메소드 구현을 게시 할 수 있습니까? –
안녕하세요! Happy New Yr .. 실제로 퇴거 정책에 의존하는 대신 다른 경로를 택했습니다. CRUD 작업이있을 때마다 캐시를 재설정하고 있습니다. 그러나 여전히 위의 접근 방식이 효과가없는 이유를 알고 싶습니다. @Desai : 위의 코드를 게시했습니다 .. @ noctarius : its hazelcast.xml –