2014-04-01 2 views
1

저는 응용 프로그램 전체에서 EhCache를 사용하고 있으며 문제가 발생했습니다. "원시"데이터 (맵 및 일부 목록 트리)를 캐시해야합니다. 캐시에서 검색된 후 캐싱 된 값은 추가 처리됩니다 (일부 요소는 필터링, 재정렬 된 등).값으로 EhCache 객체를 참조로 저장하지 않습니까?

내 문제는 원래 캐시 된 값을 그대로 유지하려는 것입니다. 일부 "후 처리"에 사용하기위한 것입니다. 그래서 궁극적으로 나는 그 객체의 참조가 아닌 객체 "value/deep clone"을 저장하려고합니다.

예제 코드 :

//create a List of Maps 
List list = new ArrayList(); 

Map<String, String> map = new HashMap<String, String>(); 
map.put("key1", "v1"); 
map.put("key2", "v2"); 
list.add(map); 

//add to cache 
cache.put("cacheRegion", "list", list); 

//now add a new element to list (2nd map) 
list.add(new TreeMap()); 

//now remove 1 entry from the 1st Map 
map = (Map<String, String>) list.get(0); 
map.remove("key1"); 

list = (List) cache.get("cacheRegion", "list"); 

assertEquals("list should still have 1 element, despite adding new map after cache put", 1, list.size()); 

//check map 
map = (Map<String, String>) list.get(0); 
assertEquals("map should still contain 2 entries, as it was added to the cache", 2, map.size()); 

합니까으로 Ehcache 지원이?

M이 true로 설정 될 수있는 속성으로 Ehcache (copyOnRead)이있다

답변

1

. 캐시 구성은 다음과 같습니다.

<cache name="copyCache" 
maxElementsInMemory="10" 
eternal="false" 
timeToIdleSeconds="5" 
timeToLiveSeconds="10" 
overflowToDisk="false" 
copyOnRead="true" 
copyOnWrite="true"> 
</cache> 
관련 문제