我想做一些简单的事情,比如将内容存储在缓存中,并在下次检索时检索它。出于某种原因,第一次一切正常,第二次调用时,高速缓存文件中的所有内容都将被删除,并且会再次创建缓存。这是我的Ehcache配置文件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>
的代码实际上创建了2个文件一只叫mycache.index,另一个叫mycache.data。将值放入缓存的代码如下所示。
Cache cache = cacheManager.getCache("mycache");
Element myElement= new Element("KEY1","This will be stored in cache");
cache.put(myElement);
难道有人请指出事情会出错吗?
我想每次都使用相同的存储缓存文件,并且只有当数据文件不存在时才创建一个新文件。
完美的答案,谢谢。问题已经解决 –
@sivaraman:在思考这个EhCache设计时,我得出结论,每次将某些东西放入缓存时刷新到磁盘是有效的(缓存应该非常快,对吗?),所以我们可以原谅EhCache这个小API不清晰。 –