我正在使用 Hibernate 4.1.1.Final 与 Spring MVC 3.1.x 并使用第一级和第二级缓存。我使用注释来配置我的域对象以进行缓存操作。但缓存不会在磁盘上存储任何内容。
这是我的ehcache.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<!--
<diskStore path="java.io.tmpdir"/>
-->
<diskStore path="java.io.tmpdir/ehcache"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
</ehcache>
休眠缓存属性:
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
域对象的基于Annonation的配置:
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
/ tmp文件夹中没有名为** ehcache 的文件夹:**
答案 0 :(得分:1)
只有当对象在内存中保存了maxElementsInMemory
个对象时,EhCache才会将对象存储到磁盘上。你确定这么多的对象真的被缓存了,因为只有在这之后,EhCache才会开始在磁盘上存储对象。