Hibernate---二級緩存實例

首先需要在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標籤裏面的第一個

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章