Напишите ценность для постоянного диска. Выключите.
Код: Выделить всё
private static void testCacheWrite() {
// create the cache manager from our configuration
URL url = TestBed.class.getClass().getResource("/resource/ehcache.xml");
CacheManager manager = CacheManager.create(url);
// check to see if our cache exits, if it doesn't create it
Cache testCache = null;
if (!manager.cacheExists("test")) {
System.out.println("No cache found. Creating cache...");
int maxElements = 50000;
testCache = new Cache("test", maxElements,
MemoryStoreEvictionPolicy.LFU, true, null, true, 60, 30,
true, Cache.DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS, null);
manager.addCache(testCache);
// add an element to persist
Element el = new Element("key", "value");
testCache.put(el);
testCache.flush();
System.out.println("Cache to disk. Cache size on disk: " +
testCache.getDiskStoreSize());
} else {
// cache exists so load it
testCache = manager.getCache("test");
Element el = testCache.get("key");
if (null == el) {
System.out.print("Value was null");
return;
}
String value = (String) el.getObjectValue();
System.out.println("Value is: " + value);
}
manager.shutdown();
}
< /code>
И вот моя конфигурация кэша (ehcache.xml< /code>
Несмотря на то, что я вижу файлы test.index и test.data на диске после первого запуска, вывод с этой функции всегда является следующим (он, кажется, никогда не загружает кэш с диска): < /p>
Не найдено. Создание кэша ...
кэш на диск. Размер кэша на диске: 2
Я, должно быть, здесь что -то глупо, но я не уверен, что!
Подробнее здесь: https://stackoverflow.com/questions/172 ... isk-issues
Мобильная версия