EhCache配置文件



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

CacheManager配置
==========================


一個ehcache.xml 相當於一個單個的CacheManager

學習下面的說明或者ehcache構架(ehcache.xsd)怎樣配置
系統資源標識在這個文件中能被具體制定,當配置被加載時,他們將會被替換。例如 multicastGroupPort=${multicastGroupPort}被環境變量的系統屬性替換,或是使用如-DmulticastGroupPort=4446命令行開關指定一個系統屬性。

<ehcache>的屬性如下:

* name – CacheManager的可選名稱。這個名稱起初主要是用於文檔記錄或辨別Terracotta集羣狀態。對於Terracotta集羣的緩存,一組CacheManager名稱和cache名稱唯一的鑑定了一個特定的存儲於Terracotta集羣存儲器的緩存。

* updateCheck – 一個可選的boolean標識符,指定這個CacheManager是否通過Internet檢查Ehcache的新版本。如果沒有特別指明,updateCheck="true".

* monitoring – 一個可選的設置,決定CacheManager是否應該自動的用系統MBean服務器註冊SampledCacheMBean。當下,這個監測。只有當使用Terracotta集羣和使用Terracotta Developer Console時纔有用。使用"autodetect"值,Terracotta集羣的出現將被檢測和監視,並通過Developer控制檯激活。其他允許的值有:"on" 和 "off"。默認爲"autodetect"。當使用JMX監測時,這個設置不會產生任何作用。

* dynamicConfig – 一個可選設置,能夠使與這個CacheManager相關聯的動態配置失活。這個設置的默認值是true-例如,動態配置是激活的。動態配置的緩存通過緩存的配置對象讓他們的TTI, TTL 和maximum disk 和in-memory capacity在運行時改變。
-->
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true" monitoring="autodetect"
dynamicConfig="true" >

<!--
DiskStore configuration
=======================
磁盤存儲器是可選的。關閉磁盤存儲路徑創建,解釋下面的磁盤存儲器元素。
對於任何緩存,如果你已經激活了overflowToDisk或diskPersistent,就要配置磁盤存儲器。
如果他未配置,並且創建了一個需要磁盤存儲的緩存,將會發出一個警告並且java.io.tmpdir將會自動使用。
磁盤存儲器僅有一個屬性- "path"。這個路徑就是.data and .index文件被創建的目錄路徑。
如果這個路徑是下述Java系統屬性之一,他將會被運行中的VM中的值替換。爲了向後兼容,這些應該被特別規定,而不會被${token}替換語法封閉。

下列屬性翻譯:
* user.home -用戶的根目錄
* user.dir – 用戶的當前工作目錄
* java.io.tmpdir – 默認臨時文件路徑
* ehcache.disk.store.dir – 一個系統屬性,你通常用命令行指定;
例如: java -Dehcache.disk.store.dir=/u01/myapp/diskdir ...



子目錄通過如下屬性指定,例如:java.io.tmpdir/one
-->
<diskStore path="java.io.tmpdir"/>


<!--
TransactionManagerLookup configuration
======================================
TransactionManagerLookup 配置
這個類被ehcache用XA激活的ehcache來查找用於應用程序中的JTA TransactionManager。如果沒有指定類,那麼DefaultTransactionManagerLookup將以如下順序找到TransactionManager。

*GenericJNDI(例如:jboss,屬性jndiName控制TransactionManager對象的名稱來查找)
*Websphere
*Bitronix
*Atomikos
你可以提供自己的查找類實現net.sf.ehcache.transaction.manager.TransactionManagerLookup接口。
<transactionManagerLookup class="net.sf.ehcache.transaction.manager.DefaultTransactionManagerLookup" properties="" propertySeparator=":"/>

<!--
CacheManagerEventListener
=========================
指定一個CacheManagerEventListenerFactory,當緩存被增加或從CacheManager移除時被告知。

CacheManagerEventListenerFactory的屬性有:
* class – 一個完全限定的工廠類名。
* properties – 逗號隔開的屬性只對工廠有意義。
overflowToDisk:設置元素是否能溢出磁盤,當存儲器容量達到最大存儲限制。

如下屬性和元素是可選的。

timeToIdleSeconds:
Sets the time to idle for an element before it expires.
設置一個元素在過期前的空閒時間
i.e. The maximum amount of time between accesses before an element expires
Is only used if the element is not eternal.
換言之,最大時間數在進入之後和元素過期之前這段時間之間,只有元素在非持久化時纔有用。
Optional attribute. A value of 0 means that an Element can idle for infinity.
可選屬性,0表示一個元素可以無限的空閒
The default value is 0.
默認值是0。

timeToLiveSeconds:
Sets the time to live for an element before it expires.
i.e. The maximum time between creation time and when an element expires.
Is only used if the element is not eternal.
Optional attribute. A value of 0 means that and Element can live for infinity.
The default value is 0.
在元素過期之前,設置一個存留時間。換言之,最大時間在創建時間和元素過期之間。僅用於元素非持久化。可選屬性。值爲0表示元素可無限存留,默認值是0

diskPersistent:
Whether the disk store persists between restarts of the Virtual Machine.
The default value is false.
磁盤存儲是否在虛擬機重啓後持續存在。默認只是false。

diskExpiryThreadIntervalSeconds:
The number of seconds between runs of the disk expiry thread. The default value
is 120 seconds.
秒數在運行和磁盤終止線程之間,默認值是120秒。

diskSpoolBufferSizeMB:
This is the size to allocate the DiskStore for a spool buffer. Writes are made
to this area and then asynchronously written to disk. The default size is 30MB.
Each spool buffer is used only by its cache. If you get OutOfMemory errors consider
lowering this value. To improve DiskStore performance consider increasing it. Trace level
logging in the DiskStore will show if put back ups are occurring.
這是爲後臺打印緩衝分配在DiskStore的大小。在這一區域進行寫入,並同步寫入磁盤。默認值是30M。每個後臺緩衝區僅由他的緩存使用,如出現OutOfMemory錯誤,考慮降低該值。爲了提高DiskStore性能,考慮增加它。跟蹤級別的DiskStore工作 將顯示是否推遲出現。

clearOnFlush:
whether the MemoryStore should be cleared when flush() is called on the cache.
By default, this is true i.e. the MemoryStore is cleared.
當flush()在緩存中被調用時,MemoryStore是否被清除。默認是true,即MemoryStore被清除。

memoryStoreEvictionPolicy:
Policy would be enforced upon reaching the maxElementsInMemory limit. Default
policy is Least Recently Used (specified as LRU). Other policies available -
First In First Out (specified as FIFO) and Less Frequently Used
(specified as LFU)

Cache elements can also contain sub elements which take the same format of a factory class
and properties. Defined sub-elements are:
當達到maxElementsInMemory限制時,策略將強制執行。策略是最近最少使用的算法(簡稱爲LRU)。其他的策略通用。緩存元素也可以有子元素,子元素擁有相同格式的工廠類和屬性。定義的sub-elements有:

* cacheEventListenerFactory - Enables registration of listeners for cache events, such as
put, remove, update, and expire.
* cacheEventListenerFactory – 啓用緩存事件監聽器的註冊,如put, remove, update, and expire.

* bootstrapCacheLoaderFactory - Specifies a BootstrapCacheLoader, which is called by a
cache on initialisation to prepopulate itself.
* bootstrapCacheLoaderFactory – 指定一個BootstrapCacheLoader,它被一個緩存在初始化時調用,用來預填充自己。

* cacheExtensionFactory - Specifies a CacheExtension, a generic mechansim to tie a class
which holds a reference to a cache to the cache lifecycle.
* cacheExtensionFactory – 指定一個CacheExtension,一個通用的mechansim來聯繫一個保存引用到緩存的類到緩存生命週期。

* cacheExceptionHandlerFactory - Specifies a CacheExceptionHandler, which is called when
cache exceptions occur.
* cacheExceptionHandlerFactory – 指定一個CacheExceptionHandler,每當緩存異常出現時調用。

* cacheLoaderFactory - Specifies a CacheLoader, which can be used both asynchronously and
synchronously to load objects into a cache. More than one cacheLoaderFactory element
can be added, in which case the loaders form a chain which are executed in order. If a
loader returns null, the next in chain is called.
* cacheLoaderFactory – 指定一個CacheLoader,能夠同步和異步裝載對象到一個緩存。可以添加多個cacheLoaderFactory元素,在這種情況裝載機形成一個鏈,被有序的執行。如果一個裝載機返回null,下一個鏈就被調用。

Cache Event Listeners
緩存事件監聽器

All cacheEventListenerFactory elements can take an optional property listenFor that describes
which events will be delivered in a clustered environment. The listenFor attribute has the
following allowed values:
所有的cacheEventListenerFactory元素能選取一個可選屬性listenFor描述的事件將在一個集羣環境中交付。這個listenFor屬性有如下允許的值:

* all - the default is to deliver all local and remote events
* local - deliver only events originating in the current node
* remote - deliver only events originating in other nodes
* all – 默認交付所有的本地和遠程事件
* local – 交付的只是源於當前節點的事件
* remote - 交付的只是源於其他節點

Example of setting up a logging listener for local cache events:
設置一個本地緩存事件監聽器的例子:

<cacheEventListenerFactory class="my.company.log.CacheLogger"
listenFor="local" />


Cache Exception Handling
緩存異常處理
++++++++++++++++++++++++

By default, most cache operations will propagate a runtime CacheException on failure. An
interceptor, using a dynamic proxy, may be configured so that a CacheExceptionHandler can
be configured to intercept Exceptions. Errors are not intercepted.
通常,大多數cache運行失敗將產生運行時CacheException。通過使用代理,一個攔截器應該被配置,以便於能夠配置CacheExceptionHandler攔截異常。錯誤並不被攔截。

It is configured as per the following example:
按照下面的例子配置:

<cacheExceptionHandlerFactory class="com.example.ExampleExceptionHandlerFactory"
properties="logLevel=FINE"/>

Caches with ExceptionHandling configured are not of type Cache, but are of type Ehcache only,
and are not available using CacheManager.getCache(), but using CacheManager.getEhcache().
有ExceptionHandling配置的緩存並不是典型的Cache,但卻是典型的Ehcache,並且不能使用CacheManager.getCache(),但能夠使用CacheManager.getEhcache()。


Cache Loader
緩存裝載
++++++++++++

A default CacheLoader may be set which loads objects into the cache through asynchronous and
synchronous methods on Cache. This is different to the bootstrap cache loader, which is used
only in distributed caching.
一個默認的CacheLoader應該被設置成這樣,能夠通過Cache中的同步和異步方法裝載對象到緩存中。這和僅在分佈是緩存中被用到的緩存裝載引導程序是不同的。

It is configured as per the following example:
按照如下示例配置:

<cacheLoaderFactory class="com.example.ExampleCacheLoaderFactory"
properties="type=int,startCounter=10"/>

XA Cache
++++++++

To enable an ehcache as a participant in the JTA Transaction, just have the following attribute
使ehcache作爲JTA事務的參與者,只需要如下屬性。

transactionalMode="xa", otherwise the default is transactionalMode="off"
transactionalMode="xa", 否則,默認是 transactionalMode="off"


Cache Writer
++++++++++++

A CacheWriter maybe be set to write to an underlying resource. Only one CacheWriter can be
been to a cache.
一個CacheWriter可以設置寫到底層資源中。只有一個CacheWriter能夠成爲一個cache。

It is configured as per the following example for write-through:
按照如下示例配置write-through:

<cacheWriter writeMode="write-through" notifyListenersOnException="true">
<cacheWriterFactory class="net.sf.ehcache.writer.TestCacheWriterFactory"
properties="type=int,startCounter=10"/>
</cacheWriter>

And it is configured as per the following example for write-behind:
按照如下示例配置write-behind:

<cacheWriter writeMode="write-behind" minWriteDelay="1" maxWriteDelay="5"
rateLimitPerSecond="5" writeCoalescing="true" writeBatching="true" writeBatchSize="1"
retryAttempts="2" retryAttemptDelaySeconds="1">
<cacheWriterFactory class="net.sf.ehcache.writer.TestCacheWriterFactory"
properties="type=int,startCounter=10"/>
</cacheWriter>

The cacheWriter element has the following attributes:
cacheWriter元素有如下屬性:
* writeMode: the write mode, write-through or write-behind

These attributes only apply to write-through mode:
這些屬性僅適用於write-through模式:
* notifyListenersOnException: Sets whether to notify listeners when an exception occurs on a writer operation.
* notifyListenersOnException:設置當一個寫操作出現異常時是否告知監聽器。

These attributes only apply to write-behind mode:
這些屬性僅適用於write-behind模式:

* minWriteDelay: Set the minimum number of seconds to wait before writing behind. If set to a value greater than 0,
it permits operations to build up in the queue. This is different from the maximum write delay in that by waiting
a minimum amount of time, work is always being built up. If the minimum write delay is set to zero and the
CacheWriter performs its work very quickly, the overhead of processing the write behind queue items becomes very
noticeable in a cluster since all the operations might be done for individual items instead of for a collection
of them.
* minWriteDelay:設置write-behind之前的等待最小秒數。如果設置值比0大,則允許操作建立在隊列中。和最大寫入延遲不同,通過等待的最短時間,工作將同時被建立。如果最小寫入延遲設置成0,並且CacheWriter快速執行程序,在一個集羣中處理隊列項目後的寫入開銷將會非常顯著,因爲所有的運行被單個項目完成,代替他們的一個集合。

* maxWriteDelay: Set the maximum number of seconds to wait before writing behind. If set to a value greater than 0,
it permits operations to build up in the queue to enable effective coalescing and batching optimisations.
* maxWriteDelay:設置在後面寫入之前等待的最大秒數。如設置值爲0,它允許在隊列裏建立運行程序,以便有效地合併和批量優化。

* writeBatching: Sets whether to batch write operations. If set to true, writeAll and deleteAll will be called on
the CacheWriter rather than write and delete being called for each key. Resources such as databases can perform
more efficiently if updates are batched, thus reducing load.
* writeBatching:設置是否批量寫入操作。如果設爲true,writeAll 和deleteAll將調用CacheWriter,而不是爲每個鍵調用write和delete。如果更新是批量的,諸如數據庫資源可以更高效的執行,因此減少了負荷。
* writeBatchSize: Sets the number of operations to include in each batch when writeBatching is enabled. If there are
less entries in the write-behind queue than the batch size, the queue length size is used.
* writeBatchSize:當writeBatching處於激活時,設置每批包含的操作的數目。如果write-behind隊列的實體數少於每批的數目,就使用隊列的長度。
* rateLimitPerSecond: Sets the maximum number of write operations to allow per second when writeBatching is enabled.
* rateLimitPerSecond:當writeBatching激活時,設置寫操作每秒允許的最大數目。
* writeCoalescing: Sets whether to use write coalescing. If set to true and multiple operations on the same key are
present in the write-behind queue, only the latest write is done, as the others are redundant.
* writeCoalescing: 設置是否使用寫入聯合。如果設爲true並且同樣的鍵有多個操作出現在write-behind隊列,只有最新的寫入完成,因爲其他的成了多餘的。
* retryAttempts: Sets the number of times the operation is retried in the CacheWriter, this happens after the
original operation.
* retryAttempts:設置CacheWriter中重複操作的總次數,這發生在初次操作之後。
* retryAttemptDelaySeconds: Sets the number of seconds to wait before retrying an failed operation.
* retryAttemptDelaySeconds:設置在失敗操作重試之前等待的秒數。

Cache Extension
+++++++++++++++

CacheExtensions are a general purpose mechanism to allow generic extensions to a Cache.
CacheExtensions are tied into the Cache lifecycle.
CacheExtensions是一個總的作用機制允許Cache有普通異常。CacheExtensions與Cache生命週期緊密相連。
CacheExtensions are created using the CacheExtensionFactory which has a
<code>createCacheCacheExtension()</code> method which takes as a parameter a
Cache and properties. It can thus call back into any public method on Cache, including, of
course, the load methods.
創建CacheExtensions 來使用CacheExtensionFactory,他有一個<code>createCacheCacheExtension()</code>方法可以當做一個參數一個Cache和屬性。因此CacheExtensions能夠回調所有Cache中的公有方法,當然,包括裝載方法。

Extensions are added as per the following example:
按照如下示例增加Extensions:

<cacheExtensionFactory class="com.example.FileWatchingCacheRefresherExtensionFactory"
properties="refreshIntervalMillis=18000, loaderTimeout=3000,
flushPeriod=whatever, someOtherProperty=someValue ..."/>

Terracotta Clustering
+++++++++++++++++++++

Cache elements can also contain information about whether the cache can be clustered with Terracotta.
The <terracotta> sub-element has the following attributes:
Cache元素也包含了有關是否緩存能和Terracotta聚集的信息。<terracotta>子元素有如下屬性:

* clustered=true|false - indicates whether this cache should be clustered with Terracotta. By
default, if the <terracotta> element is included, clustered=true.
* clustered=true|false – 顯示這個cache是否應該和Terracotta聚集。如果包括<terracotta>元素,默認的是clustered=true。
* valueMode=serialization|identity - indicates whether this cache should be clustered with
serialized copies of the values or using Terracotta identity mode. By default, values will
be cached in serialization mode which is similar to other replicated Ehcache modes. The identity
mode is only available in certain Terracotta deployment scenarios and will maintain actual object
identity of the keys and values across the cluster. In this case, all users of a value retrieved from
the cache are using the same clustered value and must provide appropriate locking for any changes
made to the value (or objects referred to by the value).
* valueMode=serialization|identity – 指出是否這個cache和值的序列化拷貝聚合或者使用Terracotta鑑定模式。通常,值將會在序列化模式中緩存,這和其他的再生Ehcache模式相似。身份模式只有在某些Terracotta部署方案中有效,並且通過集羣保持實際對象身份的鍵和值。在這種情況下,所有從緩存取值的用戶都使用相同的集羣值,並且必須對值(或者值所引用的對象)的任何改變提供了合適的鎖定。
* synchronousWrites=true|false - When set to true, clustered caches use
Terracotta SYNCHRONOUS WRITE locks. Asynchronous writes (synchronousWrites="false") maximize performance by
allowing clients to proceed without waiting for a "transaction received" acknowledgement from the server.
Synchronous writes (synchronousWrites="true") maximize data safety by requiring that a client receive server
acknowledgement of a transaction before that client can proceed. If coherence mode is disabled using
configuration (coherent="false") or through the coherence API, only asynchronous writes can occur
(synchronousWrites="true" is ignored). By default this value is false (i.e. clustered caches use normal
Terracotta WRITE locks).
* synchronousWrites=true|false – 當設爲true時,緩存集羣使用Terracotta SYNCHRONOUS WRITE鎖。異步寫入(synchronousWrites="false")最大的性能允許客戶端繼續而無需等待"transaction received"服務器的迴應。同步寫入(synchronousWrites="true")最大數據安全性,要求客戶端再繼續之前接收服務器端的事務響應。如果coherence模式不能使用配置(coherent="false")或者通過coherence API,僅異步寫入能夠存在(synchronousWrites="true"被忽略)。通常,這個值爲false(例. 聚集緩存使用正常的Terracotta WRITE鎖)。
* coherent=true|false - indicates whether this cache should have coherent reads and writes with guaranteed
consistency across the cluster. By default, its value is true. If this attribute is set to false
(or "incoherent" mode), values from the cache are read without locking, possibly yielding stale data.
Writes to a cache in incoherent mode are batched and applied without acquiring cluster-wide locks,
possibly creating inconsistent values across cluster. Incoherent mode is a performance optimization
with weaker concurrency guarantees and should generally be used for bulk-loading caches, for loading
a read-only cache, or where the application that can tolerate reading stale data. This setting overrides
coherentReads, which is deprecated.
* coherent=true|false – 指出是否這個緩存應使讀和寫前後一致並通過集羣確保其一致性。通常默認值是true。如這個屬性被設爲false(或"incoherent"模式),緩存裏沒有鎖定直接讀取的值,可能產生壞的數據。隨着併發保證的減弱,Incoherent模式是最優化性能,應該用於bulk-loading緩存,用於裝載一個只讀緩存,或用於程序中能夠容忍讀取損壞數據的地方。這個設置重載了coherentReads,這是不贊成的。
* copyOnRead=true|false - indicates whether cache values are deserialized on every read or if the
materialized cache value can be re-used between get() calls. This setting is useful if a cache
is being shared by callers with disparate classloaders or to prevent local drift if keys/values
are mutated locally w/o putting back to the cache. NOTE: This setting is only relevant for caches
with valueMode=serialization
* copyOnRead=true|false – 指出是否每個讀出的緩存值是反序列化的,或者,是否具體的緩存值能夠在get()調用之間被重用。這個設置很有用,如果一個緩存被不同的類裝載器的調用者共享,或是阻止本地偏移如果鍵/值被組織本地w/o放回緩存。注意:這個設置僅對valueMode=serialization的緩存有意義。


Simplest example to indicate clustering:
最簡單的集羣實例:
<terracotta/>

To indicate the cache should not be clustered (or remove the <terracotta> element altogether):
指明緩存不被聚集(或一起移除<terracotta>元素)
<terracotta clustered="false"/>

To indicate the cache should be clustered using identity mode:
表示使用模式聚集緩存:
<terracotta clustered="true" valueMode="identity"/>

To indicate the cache should be clustered using incoherent mode for bulk load:
對大量的裝載使用incoherent模式聚集緩存。
<terracotta clustered="true" coherent="false"/>

To indicate the cache should be clustered using synchronous-write locking level:
使用synchronous-write鎖定水平應該聚集緩存。
<terracotta clustered="true" synchronousWrites="true"/>
-->

<!--
Mandatory Default Cache configuration. These settings will be applied to caches
created programmtically using CacheManager.add(String cacheName).
強制預設緩存配置。這個設置將應用於緩存創建CacheManager.add(String cacheName)。

The defaultCache has an implicit name "default" which is a reserved cache name.
defaultCache有一個內涵的名稱“default”,是一個預設的緩存名稱。
-->
<defaultCache
maxElementsInMemory="0"
eternal="false"
timeToIdleSeconds="1200"
timeToLiveSeconds="1200">
<terracotta/>
</defaultCache>

<!--
Sample caches. Following are some example caches. Remove these before use.
緩存樣本。以下是一些緩存實例,在使用前刪掉這些。
-->

<!--
Sample cache named sampleCache1
This cache contains a maximum in memory of 10000 elements, and will expire
an element if it is idle for more than 5 minutes and lives for more than
10 minutes.
緩存實例名爲sampleCache1,這個緩存的最大存儲量爲10000個元素,如果一個元素空閒時間超過5分鐘就會失效並且生命週期超過10分鐘。

If there are more than 10000 elements it will overflow to the
disk cache, which in this configuration will go to wherever java.io.tmp is
defined on your system. On a standard Linux system this will be /tmp"
如果超過了10000個元素,磁盤緩存將會溢出,在這個緩存中,這個配置將找到你係統中任何定義java.io.tmp的地方。在標準的Linux系統中,這將會是/tmp"。


-->
<cache name="sampleCache1"
maxElementsInMemory="10000"
maxElementsOnDisk="1000"
eternal="false"
overflowToDisk="true"
diskSpoolBufferSizeMB="20"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
/>


<!--
Sample cache named sampleCache2
實例緩存sampleCache2
This cache has a maximum of 1000 elements in memory. There is no overflow to disk, so 1000
is also the maximum cache size. Note that when a cache is eternal, timeToLive and
timeToIdle are not used and do not need to be specified.
這個緩存的最大存儲容量是1000個元素。沒有磁盤溢出,因此,1000也是緩存的最大長度。要注意的是,當緩存持久化後, timeToLive和timeToIdle將不被使用,並且不需要特別指定。
-->
<cache name="sampleCache2"
maxElementsInMemory="1000"
eternal="true"
overflowToDisk="false"
memoryStoreEvictionPolicy="FIFO"
/>


<!--
Sample cache named sampleCache3. This cache overflows to disk. The disk store is
persistent between cache and VM restarts. The disk expiry thread interval is set to 10
minutes, overriding the default of 2 minutes.
示例sampleCache3。這個緩存溢出到磁盤。磁盤存儲在緩存和VM重啓的時候是持續的。磁盤期滿間隔設置爲10分鐘,覆蓋原來的2分鐘。
-->
<cache name="sampleCache3"
maxElementsInMemory="500"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="1"
memoryStoreEvictionPolicy="LFU"
/>

<!--
Sample Terracotta clustered cache named sampleTerracottaCache.
This cache uses Terracotta to cluster the contents of the cache.
Terracotta集羣緩存示例sampleTerracottaCache。這個緩存使用Terracotta聚集緩存內容。
-->
<cache name="sampleTerracottaCache"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="1800"
overflowToDisk="false">

<terracotta/>
</cache>

<!--
Sample xa enabled cache name xaCache
Xa激活緩存示例xaCache
-->

<cache name="xaCache"
maxElementsInMemory="500"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="1"
transactionalMode="xa">
<terracotta clustered="true"/>
</cache>


</ehcache>



設置完全限定類名被註冊爲CacheManager事件監聽器。

事件包括:
* adding a Cache增加一個緩存
* removing a Cache移除一個緩存
設置元素是否持久化,如果持久化,將忽視超時並且元素永不過期。
回調監聽器的方法有同步和異步兩種。安全的處理潛在的麻煩和線程安全問題將是實施者的責任,這依取決於他們的監聽器在幹什麼。

如果沒有類指定,就不會創建監聽器。這裏沒有默認值。
<cacheManagerEventListenerFactory class="" properties=""/>

<!--
TerracottaConfig
========================
maxElementsOnDisk:

設置磁盤存儲器維持的對象的最大數目。默認是0,意味着沒有限制。
eternal:
激活Terracotta集羣選項)

注意:你需要安裝運行一個或多個Terracotta服務器來使用Terracotta集羣。
參看http://www.terracotta.org/web/display/orgsite/Download


使用多個Terracotta服務器實例URLs(容錯能力)的例子
<terracottaConfig url="host1:9510,host2:9510,host3:9510"/>
maxElementsInMemory:

設置創建到存儲器中的對象的最大數目。
在ehcache配置文件中嵌入一個Terracotta配置文件簡單的放置一個普通的Terracotta XML配置到<terracottaConfig>元素中。

Example:
<terracottaConfig>
<tc-config>
<servers>
<server host="server1" name="s1"/>
<server host="server2" name="s2"/>
</servers>
<clients>
<logs>app/logs-%i</logs>
</clients>
</tc-config>
</terracottaConfig>
更多的Terracotta信息,參看Terracotta文檔。
-->
<terracottaConfig url="localhost:9510"/>

<!--
Cache configuration
===================

The following attributes are required.
如下屬性都需要:
name:

設置緩存的名稱。用於鑑定緩存,他必須是唯一的。

指定一個TerracottaConfig用於爲CacheManager配置Terracotta運行時。

配置文件可以通過兩種主要方式指定:通過引用配置文件或者使用Terracotta嵌入式配置文件。

使用URL屬性指定一個配置資源(或者多個)的引用。URL屬性必須包含一個逗號隔開的列表:
* path(Terracotta配置文件的路徑)(通常命名爲 tc-config.xml)
* URL Terracotta配置文件的URL
* <server host>:<port> Terracotta服務器運行實例
最簡單的例子指出這臺機器上的一個Terracotta服務器:
<terracottaConfig url="localhost:9510"/>
使用Terracotta配置文件路徑的例子:
<terracottaConfig url="/app/config/tc-config.xml"/>
使用Terracotta配置文件URL的例子:
<terracottaConfig url="http://internal/ehcache/app/tc-config.xml"/>

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