简体   繁体   中英

how to use ehcache in spring mvc with hibernate

I am new to spring-mvc and want to integrate ehcache as second level cache in hibernate. I followed this tutorial ehcache Now entries in my hibernate.xml are as follows:

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

entries in ehcache.xml are as follows:

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

we are following mvc model and in model i defined annootation

@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY,
region="department")

Now issue is how to start using this cache in service layer. I have not created hibernateUtil.java in my project. we are having web based spring-hibernate mvc application. Now how to start , i am not getting.

这个例子展示了一个整合Spring + Hibernate + EHCache的例子。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM