【发布时间】:2014-03-16 16:26:12
【问题描述】:
我是 spring-mvc 的新手,想将 ehcache 集成为 hibernate 中的二级缓存。 我跟着这个教程ehcache 现在我的 hibernate.xml 中的条目如下:
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</property>
<property name="hibernate.generate_statistics">true</property>
ehcache.xml 中的条目如下:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<diskStore path="java.io.tmpdir"/>
<!--defaultCache
eternal="false"
maxElementsInMemory="1000"
maxElementsOnDisk="10000"
overflowToDisk="true"
diskPersistent="true"
timeToLiveSeconds="300"
statistics="true"
copyOnWrite="true"
/-->
<cache name="com.payupaisa.cms.model.Event"
maxElementsInMemory="100000"
eternal="true"
overflowToDisk="false"
memoryStoreEvictionPolicy="LFU"
statistics="true"
timeToLiveSeconds="3600"
/>
</ehcache>
我们遵循 mvc 模型,并在模型中定义了注释
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY,
region="department")
现在的问题是如何在服务层开始使用这个缓存。 我没有在我的项目中创建 hibernateUtil.java。我们有基于 web 的 spring-hibernate mvc 应用程序。 现在如何开始,我不明白。
【问题讨论】:
标签: java hibernate spring-mvc ehcache