<
?
ehcache
?
?
?
xmlns:xsi
?
=
?
"http://www.w3.org/2001/XMLSchema-instance"
?
??
???
xsi:noNamespaceSchemaLocation
?
=
?
"ehcache.xsd"
?
>
?
??
?
?? ? < ? diskStore ? ? ? path ? = ? "java.io.tmpdir" ? /> ? ?? ?
?? ? < ? defaultCache ? ?? ?
???? ? maxElementsInMemory ? = ? "10000" ? ?? ?
???? ? maxElementsOnDisk ? = ? "0" ? ?? ?
???? ? eternal ? = ? "true" ? ?? ?
???? ? overflowToDisk ? = ? "true" ? ?? ?
???? ? diskPersistent ? = ? "false" ? ?? ?
???? ? timeToIdleSeconds ? = ? "0" ? ?? ?
???? ? timeToLiveSeconds ? = ? "0" ? ?? ?
???? ? diskSpoolBufferSizeMB ? = ? "50" ? ?? ?
???? ? diskExpiryThreadIntervalSeconds ? = ? "120" ? ?? ?
???? ? memoryStoreEvictionPolicy ? = ? "LFU" ? ?? ?
???? ? /> ? ?? ?
?? ? < ? cache ? ? ? name ? = ? "myCache" ? ?? ?
???? ? maxElementsInMemory ? = ? "100" ? ?? ?
???? ? maxElementsOnDisk ? = ? "0" ? ?? ?
???? ? eternal ? = ? "false" ? ?? ?
???? ? overflowToDisk ? = ? "false" ? ?? ?
???? ? diskPersistent ? = ? "false" ? ?? ?
???? ? timeToIdleSeconds ? = ? "120" ? ?? ?
???? ? timeToLiveSeconds ? = ? "120" ? ?? ?
???? ? diskSpoolBufferSizeMB ? = ? "50" ? ?? ?
???? ? diskExpiryThreadIntervalSeconds ? = ? "120" ? ?? ?
???? ? memoryStoreEvictionPolicy ? = ? "FIFO" ? ?? ?
???? ? /> ? ?? ?
</ ? ehcache ? >
?? ? < ? diskStore ? ? ? path ? = ? "java.io.tmpdir" ? /> ? ?? ?
?? ? < ? defaultCache ? ?? ?
???? ? maxElementsInMemory ? = ? "10000" ? ?? ?
???? ? maxElementsOnDisk ? = ? "0" ? ?? ?
???? ? eternal ? = ? "true" ? ?? ?
???? ? overflowToDisk ? = ? "true" ? ?? ?
???? ? diskPersistent ? = ? "false" ? ?? ?
???? ? timeToIdleSeconds ? = ? "0" ? ?? ?
???? ? timeToLiveSeconds ? = ? "0" ? ?? ?
???? ? diskSpoolBufferSizeMB ? = ? "50" ? ?? ?
???? ? diskExpiryThreadIntervalSeconds ? = ? "120" ? ?? ?
???? ? memoryStoreEvictionPolicy ? = ? "LFU" ? ?? ?
???? ? /> ? ?? ?
?? ? < ? cache ? ? ? name ? = ? "myCache" ? ?? ?
???? ? maxElementsInMemory ? = ? "100" ? ?? ?
???? ? maxElementsOnDisk ? = ? "0" ? ?? ?
???? ? eternal ? = ? "false" ? ?? ?
???? ? overflowToDisk ? = ? "false" ? ?? ?
???? ? diskPersistent ? = ? "false" ? ?? ?
???? ? timeToIdleSeconds ? = ? "120" ? ?? ?
???? ? timeToLiveSeconds ? = ? "120" ? ?? ?
???? ? diskSpoolBufferSizeMB ? = ? "50" ? ?? ?
???? ? diskExpiryThreadIntervalSeconds ? = ? "120" ? ?? ?
???? ? memoryStoreEvictionPolicy ? = ? "FIFO" ? ?? ?
???? ? /> ? ?? ?
</ ? ehcache ? >
???
diskStore ?:指定數據存儲位置,可指定磁盤中的文件夾位置
defaultCache?: 默認的管理策略
diskStore ?:指定數據存儲位置,可指定磁盤中的文件夾位置
defaultCache?: 默認的管理策略
以下屬性是必須的:
- name: ?Cache的名稱,必須是唯一的(ehcache會把這個cache放到HashMap里)。
-
maxElementsInMemory:
?
在內存中緩存的element的最大數目。?
-
maxElementsOnDisk:
?
在磁盤上緩存的element的最大數目,默認值為0,表示不限制。?
-
eternal:
?
設定緩存的elements是否永遠不過期。如果為true,則緩存的數據始終有效,如果為false那么還要根據timeToIdleSeconds,timeToLiveSeconds判斷。?
- overflowToDisk: ?如果內存中數據超過內存限制,是否要緩存到磁盤上。
以下屬性是可選的:
?
- timeToIdleSeconds: ?對象空閑時間,指對象在多長時間沒有被訪問就會失效。只對eternal為false的有效。默認值0,表示一直可以訪問。
- timeToLiveSeconds: ?對象存活時間,指對象從創建到失效所需要的時間。只對eternal為false的有效。默認值0,表示一直可以訪問。
- diskPersistent: ?是否在磁盤上持久化。指重啟jvm后,數據是否有效。默認為false。
- diskExpiryThreadIntervalSeconds: ?對象檢測線程運行時間間隔。標識對象狀態的線程多長時間運行一次。
- diskSpoolBufferSizeMB: ?DiskStore使用的磁盤大小,默認值30MB。每個cache使用各自的DiskStore。
- memoryStoreEvictionPolicy: ?如果內存中數據超過內存限制,向磁盤緩存時的策略。默認值LRU,可選FIFO、LFU。
緩存的3 種清空策略
?:
FIFO?,first in first out (先進先出).
LFU?, Less Frequently Used (最少使用).意思是一直以來最少被使用的。緩存的元素有一個hit 屬性,hit 值最小的將會被清出緩存。
LRU?,Least Recently Used(最近最少使用). (ehcache 默認值).緩存的元素有一個時間戳,當緩存容量滿了,而又需要騰出地方來緩存新的元素的時候,那么現有緩存元素中時間戳離當前時間最遠的元素將被清出緩存。
FIFO?,first in first out (先進先出).
LFU?, Less Frequently Used (最少使用).意思是一直以來最少被使用的。緩存的元素有一個hit 屬性,hit 值最小的將會被清出緩存。
LRU?,Least Recently Used(最近最少使用). (ehcache 默認值).緩存的元素有一個時間戳,當緩存容量滿了,而又需要騰出地方來緩存新的元素的時候,那么現有緩存元素中時間戳離當前時間最遠的元素將被清出緩存。