캐시에 무엇인가를 저장하고 다음에 그것을 검색하는 것과 같은 간단한 작업을 수행하려고합니다. 어떤 이유로 모든 것이 정상적으로 작동하며 두 번째 호출 될 때 캐시 파일의 모든 내용이 제거되고 캐시가 다시 생성됩니다. 여기 내으로 Ehcache 설정이 코드는 실제로이 개 파일을 하나의 이름 mycache.index 다른 이름 mycache.data를 생성Ehcache가 파일에 아무것도 저장하지 않음
<ehcache>
<diskStore path="<TEMP_DIR_PATH>" />
<defaultCache maxElementsInMemory="10000" eternal="true"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
maxElementsOnDisk="10000000" diskPersistent="true"
diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />
<cache name="mycache" maxElementsInMemory="1" eternal="true"
overflowToDisk="true" timeToIdleSeconds="300" timeToLiveSeconds="600"
diskPersistent="true" diskExpiryThreadIntervalSeconds="1"
memoryStoreEvictionPolicy="LFU"/>
</ehcache>
파일입니다. 값을 캐시에 저장하는 코드는 다음과 같습니다.
Cache cache = cacheManager.getCache("mycache");
Element myElement= new Element("KEY1","This will be stored in cache");
cache.put(myElement);
누군가가 일이 잘못 될 수 있음을 지적 할 수 있습니까?
매번 동일한 저장된 캐시 파일을 사용하고 데이터 파일이없는 경우에만 새 파일을 만들려고했습니다.
완벽한 답변 감사합니다. 문제가 해결되었습니다 –
@sivaraman :이 EhCache 디자인에 대해 생각하면서 캐시에 넣을 때마다 디스크로 플러시하는 것이 효과적입니다 (캐시가 정말 빨라야합니다.) 그래서 우리는 EhCache를이 용서할 수 있습니다 불명예. –