**Spring集成hibernate时,缓存的配置方法如下:

Spring 中配置文件applicationContext.xml配置:

<prop key="hibernate.cache.use_query_cache">true</prop> 

<prop key="hibernate.cache.use_second_level_cache">true</prop> 

 <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> 

<propkey="hibernate.cache.configurationResourceName">ehcache.xml</prop>                                        

ehcache.xml配置如下

<ehcache>

 <diskStore path="java.io.tmpdir"/>

 <!--

        eternal:元素是否永久的;

        MemoryStoreEvictionPolicy:default is LRU

    -->

 <defaultCache         maxElementsInMemory="10000"

            eternal="false"            timeToIdleSeconds="120"            timeToLiveSeconds="120"

            overflowToDisk="true"            diskPersistent="false"           diskExpiryThreadIntervalSeconds="120"

            memoryStoreEvictionPolicy="LRU"/>

 <cache name="cn.hnisi.persistence.mmedia.Dmtjbxx"

               maxElementsInMemory="500"               eternal="false"

               timeToIdleSeconds="2400"      timeToLiveSeconds="3600"

               overflowToDisk="false"/>

 <cache name="org.hibernate.cache.StandardQueryCache"

        maxElementsInMemory="50" eternal="false" timeToIdleSeconds="600"

        timeToLiveSeconds="1200" overflowToDisk="false"/>

 <cache name="org.hibernate.cache.UpdateTimestampsCache"

        maxElementsInMemory="500" eternal="true" overflowToDisk="false"/>

</ehcache>