EhCache配置文件
博客专区 > china008 的博客 > 博客详情
EhCache配置文件
china008 发表于4年前
EhCache配置文件
  • 发表于 4年前
  • 阅读 15
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

<?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 – 一个系统属性,你通常用命令行指定;

操作系统不同 这个系统属性所表示的目录也不同
On Windows: java.io.tmpdir:[C:\DOCUME~1\joshua\LOCALS~1\Temp\]

On Solaris: java.io.tmpdir:[/var/tmp/]

On Linux: java.io.tmpdir: [/tmp]

On Mac OS X: java.io.tmpdir: [/tmp]

例如: 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"/>

共有 人打赏支持
粉丝 6
博文 182
码字总数 30406
×
china008
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: