나는 ehcache에 넣고 싶은 100 개의 항목 (문자열) 목록을 가지고있다. 1 시간 후에 만료되도록 설정합니다. 그 후에 데이터베이스를 읽고 캐시를 새로 고치고 싶습니다.ehcache를 사용하여 데이터를 다시로드하려면 어떻게해야합니까?
이 작업을 수행하는 방법에 대한 예제를 찾을 수 없었습니다.
누구 하나 알고 있습니까?
감사
다음나는 ehcache에 넣고 싶은 100 개의 항목 (문자열) 목록을 가지고있다. 1 시간 후에 만료되도록 설정합니다. 그 후에 데이터베이스를 읽고 캐시를 새로 고치고 싶습니다.ehcache를 사용하여 데이터를 다시로드하려면 어떻게해야합니까?
이 작업을 수행하는 방법에 대한 예제를 찾을 수 없었습니다.
누구 하나 알고 있습니까?
감사
다음는 http://ehcache.org/apidocs/net/sf/ehcache/config/CacheConfiguration.html#timeToLiveSeconds(long)
그것은 다음은 기본 캐시 http://ehcache.org/apidocs/net/sf/ehcache/Cache.html#Cache%28java.lang.String,%20int,%20boolean,%20boolean,%20long,%20long%29
의 생성자에서 해당 인수되어있다 캐시에 요소의 살아있는 시간을 설정 CacheConfiguration의 방법입니다 부분적인 캐시의 요소 값 - 정확한 요소에도 지정할 수 있습니다. http://ehcache.org/apidocs/net/sf/ehcache/Element.html#setTimeToLive(int
여기에 그것을 사용의 작은 예입니다
import java.util.concurrent.TimeUnit;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
public class EhCacheFixedExpirationTest {
public static void main(String[] args) {
CacheManager cacheManager = new CacheManager();
Cache testCache = new Cache("testCache", 100, false, false, 10, 10);
cacheManager.addCache(testCache);
Element element = new Element("1", "20");
element.setTimeToLive(1);
testCache.put(element);
long start = System.nanoTime();
while (testCache.get("1") != null) {
//wait
}
System.out.println(TimeUnit.MILLISECONDS.convert((System.nanoTime() - start), TimeUnit.NANOSECONDS));
}
}
출력은 거의 항상 1000, 그래서 정밀도는 오히려 좋다. Is used Ehcache 2.4.6
cache element timeout과 함께 SelfPopulatingCache을 사용하여 원하는 것을 만족시킬 수 있습니다.