2017-09-04 12 views
0

요구 사항 : 캐싱 중에 캐싱을 위해 제공된 최대 힙 크기가 초과되면 디스크로 오버 플로우되어 그곳에서 가져와야합니다. 내으로 Ehcache 구성 :스프링 ehcache - 디스크에서 캐시를 검색하지 않습니다.

cache: 
timeToLiveSeconds: 3600 
ehcache: 
maxBytesLocalHeap: 1M 
setMaxBytesLocalDisk: 5G 
diskStore: cacheDiskStore 

이 (이상 YML에서 제공하는 값으로 타게되는) ehcache.xml 구성입니다 :

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" name="CM1" 
updateCheck="false" maxBytesLocalHeap="1M" maxBytesLocalDisk="1M" maxEntriesLocalDisk="100000"> 

<!-- This is a default configuration, it is re-configured by the CacheConfiguration 
    Spring Bean, using the properties from the resources/config/*.yml files. --> 

<diskStore path="cacheDiskStore" /> 

<defaultCache eternal="false" overflowToDisk="true" /> 
<cache name="cache1" > 
    <persistence strategy="localTempSwap" /> 
</cache> 
<cache name="cache2" > 
    <persistence strategy="localTempSwap" /> 
</cache> 

내가 큰 미디어 파일을 캐싱하고있다. 하지만 캐시에서 Element를 검색하려고하면 항상 null이됩니다. 이것은 캐시에서 검색하는 방법입니다.

Element elt = CacheManager.getInstance() 
      .getEhcache("<cacheName>").get(<key>); 
    if (elt != null) { 
     System.out.println("**** Retrieved from cache *****"); 
     return elt; 
    } else { 
     System.out.println("**** NOT FOUND IN CACHE *****"); 
     return null; 
    } 

캐시에서 가져 오지 않습니다. 캐시 힙 크기를 늘리면 제대로 작동합니다.. 어떤 도움이 필요합니까?

답변

1

Ehcache 2.x에서 디스크 저장소는 여전히 키의 힙을 소비합니다. 따라서 캐시 내용 중 일부는 디스크에 저장된 매핑 키와 힙의 매핑 사이에서 제거되므로 결국 일부가 제거 될 수 있습니다.

오픈 소스 디스크 저장소는 응용 프로그램이 종료 될 때 캐시 관리자가 완전히 종료 된 경우에만 다시 시작할 때 데이터를 복구합니다. 즉, CacheManager.shutdown()을 호출해야합니다.

+0

안녕하세요. 감사. 그러면이 퇴거는 어떻게 피할 수 있습니까? – hack

+0

힙 크기를 늘려 캐시 공간을 넓히면 자신의 질문에 자신을 진술합니다. 유스 케이스에 가장 적합한 정확한 양과 테스트가 결정되어야합니다. –