您的位置:首页 > 产品设计 > UI/UE

Ehcache 1.5.0 User Guide - Cache Configuration 缓存配置(2)

2009-06-26 15:12 387 查看
Ehcache 1.5.0 User Guide - Cache Configuration 缓存配置(1)

(Ehcache 1.5.0 用户指南)
E_mail:jianglike18@163.con
Blog: http://blog.csdn.net/jianglike18
qq:29396597
(注明:以下是一个ehcache.xml配置文件的例子)
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
CacheManager Configuration
(CacheManager 配置)
==========================
An ehcache.xml corresponds to a single CacheManager.
(一个ehcache.xml文件与一个CacheManager相对应。)

See instructions below or the ehcache schema (ehcache.xsd) on how to configure.
(如果配置查看下面的说明或ehcache的结构(ehcache.xsd))

System property tokens can be specified in this file which are replaced when the configuration
is loaded. For example multicastGroupPort=${multicastGroupPort} can be replaced with the
System property either from an environment variable or a system property specified with a
command line switch such as -DmulticastGroupPort=4446.
(系统属性特征可以在这个文件里设置,当配置被加载时系统属性会被替换。例如multicastGroupPort=${multicastGroupPort}可以被来自环境变量或命令行如-DmulticastGroupPort=4446的系统属性替换。)

DiskStore configuration
=======================

The diskStore element is optional. It must be configured if you have overflowToDisk
or diskPersistent enabled for any cache. If it is not configured, a warning will be
issues and java.io.tmpdir will be used.
(DiskStore 配置
=======================
diskStore元素是可选的。如果对于任何一个缓存你使overflowToDisk,diskPersistent可用,那么你必须配置diskStore元素。如果没有配置,会发出一个警告并使用java的临时目录java.io.tmpdir。


diskStore has only one attribute - "path". It is the path to the directory where .data and .index files will be created.
If the path is a Java System Property it is replaced by its value in the running VM.

(diskStore 只有一个属性“path”。后缀为.data 和 .index的文件都在该目录下创建。)

The following properties are translated:
* user.home - User's home directory
* user.dir - User's current working directory
* java.io.tmpdir - Default temp file path

(解释了下面的属性:
* user.home - 用户的主目录
* user.dir – 用户当前的工作目录
* java.io.tmpdir – 默认的临时目录)

The following properties are translated:
* user.home - User's home directory
* user.dir - User's current working directory
* java.io.tmpdir - Default temp file path
* 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

(解释了下面的属性:
* 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"/>

<!--
CacheManagerEventListener
=========================
Specifies a CacheManagerEventListenerFactory, be used to create a CacheManagerPeerProvider,
which is notified when Caches are added or removed from the CacheManager.

(CacheManagerEventListener (缓存事件监听)
设置CacheManagerEventListenerFactory用于创建一个CacheManagerPeerProvider,用于提醒当CacheManager中的缓存增加或者删除时


The attributes of CacheManagerEventListenerFactory are:
* class - a fully qualified factory class name
* properties - comma separated properties having meaning only to the factory.

(CacheManagerEventListenerFactory类的属性:
*class:完整的工厂类名称
*properties:逗号分割该工厂类属性含义


Sets the fully qualified class name to be registered as the CacheManager event listener.
The events include:
* adding a Cache
* removing a Cache

(设置完整的类名注册为CacheManager的事件监听。
包含如下事件:
* 增加缓存
* 移除缓存)

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.

(监听的回调函数可以是同步和异步。实现者有职责安全处理潜在的性能和线程安全问题,但这依赖监听器是怎么做的。
如果没有指定监听类,监听器就不会被创建,也没有默认的。)

-->
<cacheManagerEventListenerFactory class="" properties=""/>

<!--
CacheManagerPeerProvider
========================
(Enable for distributed operation)

Specifies a CacheManagerPeerProviderFactory which will be used to create a
CacheManagerPeerProvider, which discovers other CacheManagers in the cluster.

(CacheManagerPeerProvider
========================
设置一个用于创建CacheManagerPeerProvider类的工厂类CacheManagerPeerProviderFactory,在集群环境里CacheManagerPeerProvider类用于查找其他的CacheManagers。


The attributes of cacheManagerPeerProviderFactory are:
* class - a fully qualified factory class name
* properties - comma separated properties having meaning only to the factory.

(CacheManagerEventListenerFactory类的属性:
*class:完整的工厂类名称
*properties:逗号分割属性,该属性仅对该工厂类有意义


Ehcache comes with a built-in RMI-based distribution system with two means of discovery of
CacheManager peers participating in the cluster:
* automatic, using a multicast group. This one automatically discovers peers and detects
changes such as peers entering and leaving the group
* manual, using manual rmiURL configuration. A hardcoded list of peers is provided at
configuration time.

(Ehcache 配备了内置的基于RMI(远程方法接口)分布式机制,该机制有两种发现集群中共享的CacheManager peer对象的方法:
*自动的,使用多点传送组。这一个自动发现同行和检测的变化,如同龄人进入和离开组
*手动的,使用手动的rmiURL配置。在配置时固定的peer组就被提供了。


Configuring Automatic Discovery:
Automatic discovery is configured as per the following example:
(配置自动查找:
自动查找按照如下的例子进行配置)

<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, timeToLive=32"/>

Valid properties are:(有效的参数:)
* peerDiscovery (mandatory) - specify "automatic"
* multicastGroupAddress (mandatory) - specify a valid multicast group address
* multicastGroupPort (mandatory) - specify a dedicated port for the multicast heartbeat
traffic
* timeToLive - specify a value between 0 and 255 which determines how far the packets will
propagate.

(* peerDiscovery(强制的)-设置成“automatic”值
* multicastGroupAddress (强制的) –设置正确的多点传送组地址
* multicastGroupPort (强制的) – 为组播流量心跳设置一个专门的端口。
* timeToLive – 设置一个0到255的值,该值决定信息发送的网络范围。


By convention, the restrictions are:(根据习惯,约束如下:)
0 - the same host (0 – 相同的主机)
1 - the same subnet (1- 相同的子网)
32 - the same site (32 – 相同的站点)
64 - the same region (64 – 相同的区域)
128 - the same continent (128 – 系统的地区)
255 – unrestricted(255 – 无限制)

Configuring Manual Discovery:(配置手动查找:)
Manual discovery is configured as per the following example:(手动查找按照如下的例子进行配置)
<cacheManagerPeerProviderFactory class=
"net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//server1:40000/sampleCache1|//server2:40000/sampleCache1
| //server1:40000/sampleCache2|//server2:40000/sampleCache2"
propertySeparator="," />

Valid properties are:(有效参数:)
* peerDiscovery (mandatory) - specify "manual"(设置“manual”)
* rmiUrls (mandatory) - specify a pipe separated list of rmiUrls, in the form //hostname:port
The hostname is the hostname of the remote CacheManager peer. The port is the listening
port of the RMICacheManagerPeerListener of the remote CacheManager peer.
(设置通道,各rmiUrls通道按“//主机名:端口”形式以逗号分隔。主机名是远程CacheManager peer的名字。端口是远程CacheManager peer的RMICacheManagerPeerListener监听端口。)
-->
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic,
multicastGroupAddress=230.0.0.1,
multicastGroupPort=4446, timeToLive=1"
propertySeparator=","
/>
<!--
CacheManagerPeerListener
========================
(Enable for distributed operation)
Specifies a CacheManagerPeerListenerFactory which will be used to create a
CacheManagerPeerListener, which
listens for messages from cache replicators participating in the cluster.

(CacheManagerPeerListener
用于分布式操作
设置一个用于创建CacheManagerPeerListener监听 对象的CacheManagerPeerListenerFactory工厂类,CacheManagerPeerListener对象监听来自集群中缓存复制分享的消息。


The attributes of cacheManagerPeerListenerFactory are:
class - a fully qualified factory class name
properties - comma separated properties having meaning only to the factory.

(cacheManagerPeerListenerFactory类的属性:
class – 完成有效的工厂类名
properties -逗号分割属性,该属性仅对该工厂类有意义。


Ehcache comes with a built-in RMI-based distribution system. The listener component is
RMICacheManagerPeerListener which is configured using
RMICacheManagerPeerListenerFactory. It is configured as per the following example:

(Ehcache 配备了内置的基于RMI(远程方法接口)分布式机制。监听组件是用RMICacheManagerPeerListenerFactory 类配置的RMICacheManagerPeerListener类。它是按照如下的例子进行配置。)

<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=fully_qualified_hostname_or_ip,
port=40001,
socketTimeoutMillis=120000"
propertySeparator="," />

All properties are optional. They are:
* hostName - the hostName of the host the listener is running on. Specify
where the host is multihomed and you want to control the interface over which cluster
messages are received. Defaults to the host name of the default interface if not
specified.
* port - the port the listener listens on. This defaults to a free port if not specified.
* socketTimeoutMillis - the number of ms client sockets will stay open when sending
messages to the listener. This should be long enough for the slowest message.
If not specified it defaults 120000ms.

(所有的配置项都是可选的:
* hostName – 监听运行的主机名。
* port – 监听器监听的端口,如果没有指定默认为空闲的端口,)
*socketTimeoutMillis – 客户端sockets发消息到监听器后持续打开的时间,该时间对于最慢的信息应该足够长,如果没有指定默认为120000毫秒。

<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>

<!--
Cache configuration (缓存配置)
===================
The following attributes are required.(如下属性是必须的:)

name:
Sets the name of the cache. This is used to identify the cache. It must be unique.
(名称(name):)
(设置缓存的名称。用于唯一标示缓存。名字必须唯一。)
maxElementsInMemory:
Sets the maximum number of objects that will be created in memory
(内存中保持的对象数量(maxElementsInMemory):
设置内存中可以创建的最大对象数目。

maxElementsOnDisk:
Sets the maximum number of objects that will be maintained in the DiskStore
The default value is zero, meaning unlimited.
(DiskStore中保持的对象数量:
设置磁盘中可允许的最大对象数目,默认为0,即无限制。


eternal:
Sets whether elements are eternal. If eternal, timeouts are ignored and the
element is never expired.

(永久的(eternal):
设置对象是否为永久的,如果是,超时设定被忽略且对象不过期。)

overflowToDisk:
Sets whether elements can overflow to disk when the memory store
has reached the maxInMemory limit.

(转存到磁盘(overflowToDisk):
当内存达到maxInMemory的最大限制,设置元素是否可以转存到磁盘。)

The following attributes and elements are optional.
(下面的属性和元素是可选的:)

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.

(空闲最长时间(timeToIdleSeconds)
设置元素的过期之前的空闲时间,也就是说元素在访问和过期之间的最大的时间总计。仅在当元素不是永久的情况下使用。)

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.
(象生存最长时间(timeToLiveSeconds)
设置对象过期之前的生存时间。
也就是说,元素从创建到过期之间的最大的时间总计。
在当元素不是永久的情况下使用。可选的属性,值为0表示元素可以无限生存。
默认值为0


diskPersistent:
Whether the disk store persists between restarts of the Virtual Machine.
The default value is false.

(是否在磁盘上持久化:
指重启jvm后,数据是否有效。默认为false)

clearOnFlush:
cache parameter. It determines whether the MemoryStore should be cleared when flush()
is called on the cache. By default, the MemoryStore is cleared. Useful is you want to
back up a cache to the file system without clearing the MemoryStore.

(执行flush方法后清空:
缓存参数。当flush()方法在缓存中被调用后,决定内存存储是否被清除。默认的是被清除。
如果你想不清除内存存储的情况下,备份缓存到文件系统这个参数是比较有用的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: