【EhCache二】ehcache.xml配置详解

前端之家收集整理的这篇文章主要介绍了【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.
原文链接:https://www.f2er.com/xml/297991.html

猜你在找的XML相关文章