日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

01_MyBatis EHCache集成及所需jar包,ehcache.xml配置文件参数配置及mapper中的参数配置

發布時間:2024/9/27 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 01_MyBatis EHCache集成及所需jar包,ehcache.xml配置文件参数配置及mapper中的参数配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


1 mybatis集成時需要的jar

ehcache-core-2.6.5.jar

mybatis-ehcache-1.0.2.jar

Mybatis、日志、EHCache所需要的jar包如下:

2 EHCachemybatis集成

EHCache是一種廣泛使用java分布式緩存通用緩存,JavaEE中的一個輕量級的容器。

EHCache集成是基于ehcache-core,沒有任何其它第三方應用程序。

想使用EHCache到她們的應用程序的用戶,必須下載EHCachezip bundle,解壓它添加這些jarsclasspath路徑下。使用Apache Maven的用戶只需要在pom.xml文件中添加如下內容:

<dependencies> ? ... ? <dependency> ??? <groupId>org.mybatis.caches</groupId> ??? <artifactId>mybatis-ehcache</artifactId> ??? <version>1.0.2</version> ? </dependency> ? ... </dependencies>

接著需要在mapperxml文件中配置如下內容:

<mapper namespace="org.acme.FooMapper">

<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>...

</mapper>

你也可以提供可以再運行動態變更的如下參數:

<mapper namespace="org.acme.FooMapper">

? ??<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>

??? <property name="timeToIdleSeconds" value="3600"/><!--1hour-->

??? <property name="timeToLiveSeconds" value="3600"/><!--1hour-->

??? <property name="maxEntriesLocalHeap" value="1000"/>

??? <property name="maxEntriesLocalDisk" value="10000000"/>

??? <property name="memoryStoreEvictionPolicy" value="LRU"/>

? </cache>

? ...

</mapper>

如果用戶需要日志緩存操作,可以插入Cachelogging version:

<mapper namespace="org.acme.FooMapper">

? <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>

? ...

</mapper>

??? 需要通xml配置文件配置EHCache的用戶,必須要在classpath路徑下放置/ehcache.xml資源。

/ehcache.xml資源沒有發現或者在加載/ehcache.xml的時候發生錯誤,將會使用默認的配置。

3 /ehcache.xml配置文件參數配置

<?xml version="1.0" encoding="UTF-8"?>

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

?? xsi:noNamespaceSchemaLocation="ehcache.xsd"

?? updateCheck="true" monitoring="autodetect" dynamicConfig="true">

?

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

??

?? <!--?

??? nameCache的唯一標識

??? maxElementsInMemory:內存中最大緩存對象數

??? maxElementsOnDisk:磁盤中最大緩存對象數,若是0表示無窮大

??? eternalElement是否永久有效,一但設置了,timeout將不起作用

??? overflowToDisk:配置此屬性,當內存中Element數量達到maxElementsInMemory時,Ehcache將會Element寫到磁盤中

??? timeToIdleSeconds:設置Element在失效前的允許閑置時間。僅當element不是永久有效時使用,可選屬性,默認值是0,也就是可閑置時間無窮大

??? timeToLiveSeconds:設置Element在失效前允許存活時間。最大時間介于創建時間

??????? 和失效時間之間。僅當element不是永久有效時使用,默認是0.,也就是element存活時間無窮大?

??? diskPersistent:是否緩存虛擬機重啟期數據?

??? diskExpiryThreadIntervalSeconds:磁盤失效線程運行時間間隔,默認是120

??? diskSpoolBufferSizeMB:這個參數設置DiskStore(磁盤緩存)的緩存區大小。默認是30MB。每個Cache都應該有自己的一個緩沖區

??? memoryStoreEvictionPolicy:當達到maxElementsInMemory限制時,Ehcache將會根據指定的策略去清理內存。默認策略是LRU(最近最少使用)。你可以設置為FIFO(先進先出)或是LFU(較少使用)?

??? -->

?? <defaultCache maxElementsInMemory="10000"

????? eternal="false"

????? timeToIdleSeconds="120"

????? timeToLiveSeconds="120"

????? overflowToDisk="true"

????? maxElementsOnDisk="10000000"

????? diskPersistent="false"

????? diskExpiryThreadIntervalSeconds="120"

????? memoryStoreEvictionPolicy="LRU" />

</ehcache>

sqlMapConfig.xml中的<settings>設置如下:

<!-- 開啟延遲加載 -->

<settings>

?? <!-- 全局的延遲加載的開關必須要開啟 -->

?? <setting name="lazyLoadingEnabled" value="true"/>

?? <!-- 積極加載設置成false -->

?? <setting name="aggressiveLazyLoading" value="false"/>

?? <!-- 開啟二級緩存, 緩存中只要是需要配置的針對的都是二級緩存 -->

?? <setting name="cacheEnabled" value="true"/>

</settings>

??? mapper文件中的內容如下:

總結

以上是生活随笔為你收集整理的01_MyBatis EHCache集成及所需jar包,ehcache.xml配置文件参数配置及mapper中的参数配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。