【EhCache二】ehcache.xml配置详解

在ehcache官网上找了多次,终于找到ehcache.xml配置元素和属性的含义说明文档了,这个文档包含在ehcache.xml的注释中!

ehcache.xml : http://ehcache.org/ehcache.xml

ehcache.xsd : http://ehcache.org/ehcache.xsd

ehcache配置文件的根元素是ehcahe

ehcache根元素的属性

1.name

an optional name for the CacheManager. The name is optional and primarily used for documentation

2.updateCheck

an optional boolean flag specifying whether this CacheManager should check for new versions of Ehcache over the Internet. If not specified,updateCheck="true".认是true

3.dynamicConfig

an optional setting that can be used to disable dynamic configuration of caches associated with this CacheManager。认是true

4.defaultTransactionTimeoutInSeconds

事务超时时间,认是15

5.maxBytesLocalHeap

optional setting that constraints the memory usage of the Caches managed by the CacheManager to use at most the specified number of bytes of the local VM's heap. 取值需要符 合正则表达式([0-9]+[bBkKmMgG]?|100%|[0-9]{1,2}%),认0,表示没有限制

6. maxBytesLocalOffheap

optional setting that constraints the offheap usage of the Caches managed by the CacheManager to use at most the specified number of bytes of the local VM's offheap memory.取 值需要符合正则表达式[0-9]+[bBkKmMgG]? ,认0,表示不限制

7. maxBytesLocaldisk

optional setting that constraints the disk usage of the Caches managed by the CacheManager to use at most the specified number of bytes of the local disk.取值需要符合正则表达式[0-9]+[bBkKmMgG]? ,认0,表示不限制

8. monitoring

an optional setting that determines whether the CacheManager should automatically register the SampledCacheMBean with the system MBean server。 认是autodetect ,可选值包括autodetect,on,off

ehcache根元素的所有属性都是可选的,除了name之外都有一个认值

ehcache根元素的子元素

1. defaultCache

2. cache

3. diskStore

4. transactionManagerLookup

5. sizeOfPolicy

6. cacheManagerPeerProviderFactory

7. cacheManagerPeerListenerFactory

8. cacheManagerEventListenerFactory

说明:

  • 这些元素cache,cacheManagerPeerProviderFactory,cacheManagerPeerListenerFactory,cacheManagerEventListenerFactory可以有多个,其它至多有1个。每个元素都可以不出现,即ehcache可以是空的xml文档。如果是空的文档,如果定义缓存?可以使用编程的方式,动态的创建Cache实例。
  • 这些元素都不是简单元素,因此它们都可以定义子元素

defaultCache的属性

1. diskExpiryThreadIntervalSeconds

The number of seconds between runs of the disk expiry thread. The default value is 120 seconds.

2. 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.

3.diskPersistent

The disk store is persistent between cache and VM restarts。That's to say,data saved in the disk will be persisted even the VM is down?

4.diskAccessstripes

5.eternal

Specify whether the elemement in the cache is never expired. Note that when a cache is eternal,timetoLive and timetoIdle are not used and do not need to be specified

6.maxElementsInMemory

7.maxEntriesLocalHeap

Specify the maximum number of elements that can stay in memory(JVM memory,kNow as heap)。指定允许在内存中存放元素的最大数量0表示不限制。这个属性也可以在运行期动态修改

8.clearOnFlush

表示在调用Cacheflush方法时是否要清空MemoryStore认为true

9.memoryStoreevictionPolicy

内存中的缓存数据清除策略。EhCache提供了两种方式:LRU,FIFO

10.overflowTodisk

Specify whether overflow to disk if the number of elements exceed in memory 。认为false。当内存里面的缓存已经达到预设的上限时是否允许将按驱除策略驱除的元素保存在硬盘上,认是LRU(最近最少使用)。当指定为false的时候表示缓存信息不会保存到磁盘上,只会保存在内存中。该属性现在已经废弃,推荐使用cache元素的子元素persistence来代替,如:<persistence strategy=”localTempSwap”/>

11.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. The default value is 0.

12.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.

13.maxElementsOndisk

14.maxEntriesLocaldisk

Sets the maximum number of objects that will be maintained in the diskStore。The default value is zero,meaning unlimited.

15.transactionalMode

事务模式,有on,off,local,xa,xa_strict五中取值,认是off

16.statistics

17.copyOnRead

Whether an Element is copied when being read from a cache.By default this is false.


18.copyOnWrite

Whether an Element is copied when being added to the cache. By default this is false.

19.cacheLoaderTimeoutMillis

20.overflowToOffheap

boolean类型,认为false。表示是否允许Cache使用非堆内存进行存储,非堆内存是不受Java GC影响的。该属性只对企业版Ehcache有用

21.maxMemoryOffheap

非堆内存的最大值

cache元素的属性

cache除了包含defaultCache元素定义的属性之外,cache元素还有几个defacultCache元素没有的属性

1. maxBytesLocalHeap

指定当前缓存能够使用的JVM堆内存的最大字节数。它的格式需要满足匹配正则表达式([0-9]+[bBkKmMgG]?|100%|[0-9]{1,2}%)

2.maxBytesLocalOffheap

指定当前缓存能够使用的JVM非堆内存的最大字节数。它的格式需要满足匹配正则表达式([0-9]+[bBkKmMgG]?|100%|[0-9]{1,2}%)

3.maxBytesLocaldisk

指定当前缓存能够使用的硬盘的最大字节数。它的格式需要满足匹配正则表达式([0-9]+[bBkKmMgG]?|100%|[0-9]{1,2}%)。它的值应该小于ehcache根元素上的这个属性的配置,如果ehache下还有其它的cache,那么分配给其它Cache的容量为ehcache.maxBytesLocaldisk - this.maxBytesLocaldisk。其它两个属性也是一样的

diskStore元素配置

diskstore元素没有子元素,同时只有一个path属性,用于指定EhCache往磁盘上存放数据的路径,认是java.io.tmpdir。

  • The diskStore element is optional. Configure it if you have disk persistence enabled for any cache or if you use unclustered indexed search.
  • If it is not configured,and a cache is created which requires a disk store,a warning will be issued and java.io.tmpdir will automatically be used.
  • diskStore has only one attribute - "path". It is the path to the directory where any required disk files will be created.
  • If the path is one of the following Java System Property it is replaced by its value in the running VM. For backward compatibility these should be specified without being enclosed in the ${token} replacement Syntax. The following properties are translated

1. user.dir - User's current working directory
2. java.io.tmpdir - Default temp file path
3. ehcache.disk.store.dir - A system property you would normally specify on the command line e.g. java -Dehcache.disk.store.dir=/u01/myapp/diskdir ...

  • Subdirectories can be specified below the property e.g. java.io.tmpdir/one
<diskStore path="java.io.tmpdir"/>

<diskStore path="/home/tom/ehcache-data-dir"/>

cacheManagerEventListenerFactory元素配置

cacheManagerEventListenerFactory作为ehcache的子元素,它监听的是CacheManager的添加删除缓存对象(Cache)的事件。同样的,cache元素的子元素cacheEventListenerFactory用于监听Cache上数据CRUD操作

  • Specifies a CacheManagerEventListenerFactory which is notified when Caches are added or removed from the CacheManager.
  • The attributes of CacheManagerEventListenerFactory are:

1. class - a fully qualified factory class nameThe fully qualified class name will be set to be registered as the CacheManager event listener.
2. properties - comma separated properties having meaning only to the factory.

  • The events include:

1. adding a Cache
2. removing a Cache

  • Callbacks to listener methods are synchronous and unsynchronized. It is the responsibility of the implementer to safely handle the potential performance and thread safety issues depending on what their listener is doing.
  • If no class is specified,no listener is created. There is no default.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇