2012-11-12 108 views
0

什么我使用休眠4.1.1.FinalSpring MVC的3.1.X并同时使用第一和第二级缓存。我使用注释为高速缓存操作配置了我的域对象。但缓存不会在磁盘上存储任何内容。休眠4.1.x版的Ehcache不存储在磁盘上

这是我的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> 

Hibernate缓存属性:

<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) 

号命名的文件夹**的Ehcache/tmp文件夹中:**

/tmp folder

回答

1

的Ehcache将存储上只有当它保存在maxElementsInMemory内存本身的对象数量的磁盘对象。你确定这么多的对象真的被缓存了,因为只有在这之后,EhCache才会开始在磁盘上存储对象。