配置文件ehcache.xml详解(1)—<Cache>

ehcache.xml中Cache部分的配置说明:


以下是cache部分最主要的配置,
<!--
Cache configuration
===================   
The following attributes are required.   
以下属性是必须的

name Cache的唯一标识名称(缓存区名称,用以区别缓存区,必须唯一)
    Sets the name of the cache. This is used to identify  the cache. It must be unique .

maxEntriesLocalHeap: 设置缓存在本地内存中最大缓存项数量,0没有限制
    Sets the maximum number of objects that will be created in memory.  0 = no limit .
    In practice no limit means Integer.MAX_SIZE (2147483647) unless the cache is distributed
    with a Terracotta server in which case it is limited by resources.

maxEntriesLocalDisk: 磁盘中的最大对象数,默认为0不限制
    Sets the maximum number of objects that will be maintained in the DiskStore
    The default value is zero, meaning unlimited.

eternal: elements是否永久有效,如果为true,timeouts将被忽略,element将永不过期
    Sets whether elements are eternal. If eternal,  timeouts are ignored and the
    element is never expired.   

The following attributes and elements are optional.   
以下属性是可选的

overflowToOffHeap: 只能用于企业版本中。设置为true,缓存将使用非堆内存,非堆内存并非由java管理,与java垃圾回收无关。默认为false。
    (boolean) This feature is available only in enterprise versions of Ehcache.
    When set to true, enables the cache to utilize  off-heap memory  storage to improve performance. Off-heap memory is not subject to Java  GC. The default value is false.

maxBytesLocalHeap: 如果设置了这个属性,maxEntriesLocalHeap将不能被利用(定义保存在java虚拟机堆内存中的最大字节数)
    Defines how many bytes the cache may use from the VM's heap. If a CacheManager  maxBytesLocalHeap has been defined, this Cache's specified  amount  will be  subtracted from the CacheManager. Other caches will share the remainder .
    This attribute's values are given as <number>k|K|m|M|g|G for  kilobytes (k|K), megabytes (m|M), or gigabytes (g|G).
    For example, maxBytesLocalHeap="2g" allots 2 gigabytes of heap memory.
    If you specify a maxBytesLocalHeap, you can't use the maxEntriesLocalHeap attribute.
    maxEntriesLocalHeap can't be used if a CacheManager maxBytesLocalHeap is set.
    Elements put into the cache will be measured in size using net.sf.ehcache.pool.sizeof.SizeOf
    If you wish to ignore some part of the object graph, see net.sf.ehcache.pool.sizeof.annotations.IgnoreSizeOf

maxBytesLocalOffHeap: 只能用于企业版本中(设置本缓存区使用的非堆内存的大小。指定此属性,将默认设置overflowToOffHeap为true。如果特别指定了overflowToOffHeap=false,将禁止使用非堆内存
    This feature is available only in enterprise versions of Ehcache.
    Sets the amount of off-heap memory this cache can use, and will reserve.   

    This setting will set overflowToOffHeap to true. Set explicitly to false to disable overflow behavior.

    Note that it is recommended to set maxEntriesLocalHeap to at least 100 elements
    when using an off-heap store, otherwise performance will be seriously degraded, and a warning will be logged.
    The minimum amount that can be allocated is 128MB. There is no maximum.   

maxBytesLocalDisk: 像maxBytesLocalHeap属性,不过指定得是存储在本地磁盘上的缓存项最大可使用的字节数
    As for maxBytesLocalHeap, but specifies the limit of disk storage this cache will ever use.

timeToIdleSeconds:失效前的空闲秒数,当eternal为false时,这个属性才有效,0为不限制
    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.

timeToLiveSeconds: 失效前的存活秒数,创建时间到失效时间的间隔为存活时间,当eternal为false时,这个属性才有效,0为不限制
    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.

diskExpiryThreadIntervalSeconds: 清理保存在磁盘上的过期缓存项目的线程的启动时间间隔,默认120秒。
    The number of seconds between runs of the disk expiry thread. The default value  is 120 seconds.

diskSpoolBufferSizeMB: 这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区(写入磁盘的内容将缓存在此区域,使用异步的方式写入磁盘;如果遇到OutOfMemory错误时,可以尝试减小这个值。改进磁盘写入性能时,尝试增加这个值;将日志级别开到trace,当DiskStore执行磁盘写入时,可以看到对应日志
    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.

clearOnFlush: 当调用flush()是否清除缓存,默认是true,即清空。
    whether the MemoryStore should be cleared when flush() is called on the cache.
    By default, this is true i.e. the MemoryStore is cleared.

statistics: 是否收集统计信息。如果需要监控缓存使用情况,应该打开这个选项。默认为关闭(统计会影响性能)。设置statistics="true"开启统计
    Whether to collect statistics. Note that this should be turned on if you are using  the Ehcache Monitor. By default statistics is turned off to favour raw performance.
    To enable set statistics="true"

memoryStoreEvictionPolicy: 内存回收策略(当缓存项达到maxEntriesLocalHeap限制时,剔除缓存项的策略),默认回收策略是:LRU最近最少使用Least Recently Used,其他策略有:先进先出First In First Out,Less Frequently Used使用频率最低
    Policy would be enforced upon reaching the maxEntriesLocalHeap 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)

copyOnRead: 当缓存项被读出时,是否返回一份它的拷贝(返回对象是缓存中对象的拷贝)。默认fasle。
    Whether an Element is copied when being read from a cache.
    By default this is false.

copyOnWrite: 当缓存项被写入时,是否写入一份它的拷贝(写入缓存的是写入对象的拷贝)。默认false
    Whether an Element is copied when being added to the cache.
    By default this is false.


    Cache persistence is configured through the persistence sub-element.  The attributes of the
    persistence element are:
通过使用<  persistence  />子元素,可以配置缓存区的持久化策略,主要属性如下:


strategy: 配置缓存区持久化的类型,可选值如下:
    Configures the type of persistence provided by the configured cache.  This must be one of the  following values:

    * localRestartable - 仅在使用Ehcache企业版时有效。启动RestartStore,拷贝所有的缓存项(包含堆和非堆中的)到磁盘中,此选项提供了缓存快速重启能力以及对磁盘上缓存的容错能力) Enables the RestartStore and copies all cache entries (on-heap and/or off-heap)  to disk. This option provides fast restartability with fault tolerant cache persistence on disk.
    It is available for Enterprise Ehcache users only.

    * localTempSwap  (当缓存容量达到上线时,将缓存对象(包含堆和非堆中的)交换到磁盘中。“ localTempSwap”并不持久化缓存内容) Swaps cache entries (on-heap and/or off-heap) to disk when the cache is full.
    "localTempSwap" is not persistent.

    * none  (不持久化缓存内容) Does not persist cache entries.

    * distributed  (按照<terracotta>标签配置的持久化方式执行。非分布式部署时,此选项不可用 Defers to the <terracotta> configuration for persistence settings. This option  is not applicable for standalone.
    
    The following example configuration shows a cache configured for localTempSwap restartability.
    <cache name="persistentCache" maxEntriesLocalHeap="1000">
        <persistence strategy="localTempSwap"/>
    </cache>


synchronousWrites: 此属性仅在strategy=“localRestartable”时有意义。默认false。设置为true,缓存写入方法在缓存项成功写入磁盘前不会返回
    When set to true write operations on the cache do not return until after the operations data has been  successfully flushed to the disk storage.  This option is only valid when used with the "localRestartable"  strategy, and defaults to false.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值