首先需要在hibernate.xml中聲明使用緩存:
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop><!-- 緩存插件 -->
<prop key="hibernate.cache.use_query_cache">true</prop><!-- 是否開啓查詢緩存 -->
然後在src目錄下添加ehcache.xml文件,文件內容:
<ehcache>
<diskStore path="C:\\cache"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
<cache name="NEVER_OVERDUE"
maxElementsInMemory="1000"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
/>
</ehcache>
最後在需要緩存的映射文件中配置:
<cache usage="read-write"/> 一般配置在class標籤裏面的第一個
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop><!-- 緩存插件 -->
<prop key="hibernate.cache.use_query_cache">true</prop><!-- 是否開啓查詢緩存 -->
然後在src目錄下添加ehcache.xml文件,文件內容:
<ehcache>
<diskStore path="C:\\cache"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
<cache name="NEVER_OVERDUE"
maxElementsInMemory="1000"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
/>
</ehcache>
最後在需要緩存的映射文件中配置:
<cache usage="read-write"/> 一般配置在class標籤裏面的第一個