Java Ehcache与defaultCache?
在我的项目中,我们使用Java Ehcache与defaultCache?,java,hibernate,ehcache,Java,Hibernate,Ehcache,在我的项目中,我们使用ehcache进行二级缓存,我们提到了标记和一些属性 ehcache.xml的示例 <ehcache> <defaultCache maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" maxEntriesLocalDisk="10000000" diskExpiryT
ehcache
进行二级缓存,我们提到了
标记和一些
属性
ehcache.xml的示例
<ehcache>
<defaultCache
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxEntriesLocalDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
<cache name="com.test.First"
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
/>
<cache name="com.test.Second"
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
/>
</ehcache>
<class-cache class="com.test.First" usage="read-only"/>
<class-cache class="com.test.Second" usage="read-only"/>
<class-cache class="com.test.Third" usage="read-only"/>
hibernate.cfg.xml的示例
<ehcache>
<defaultCache
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxEntriesLocalDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
<cache name="com.test.First"
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
/>
<cache name="com.test.Second"
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
/>
</ehcache>
<class-cache class="com.test.First" usage="read-only"/>
<class-cache class="com.test.Second" usage="read-only"/>
<class-cache class="com.test.Third" usage="read-only"/>
这里我们为com.test.Third
添加了
标记,这在ehcache.xml
文件中没有提到
这个
com.test.Third
类是否也可以通过使用defaultCache
进行缓存?在这种情况下实际上是这样的,因为Hibernate将为您完成这项工作。但是defaultCache不是为自动创建缓存而设计的。有关更多详细信息,请查看以下问题:Thaks@Nick,但令我惊讶的是,com.test.Third也因为这个问题而被缓存。谢谢。我想Hibernate为你做了创作工作。对于Hibernate 4.3.3,org.Hibernate.cache.ehcache.AbstractEhcacheRegionFactory中的getCache(字符串名称)将以编程方式添加缓存(如果没有)。无论如何,我已经调整了我的答案。。。