关于Ehcache 配置

openkk 12年前
     ehcache的默认配置文件名为ehcache.xml,也可以自己指定。配置文件比较的简单,基本上也就是常用的几个元素。    <br />    <br />    <span style="font-weight:bold;">配置元素说明:<br /> <br /> </span>diskStore:配置DiskStore,当需要使用磁盘保存的时候,需要对象实现序列化接口    <br />    <br />     属性:path 配置文件存储位置,如user.home,user.dir,java.io.tmpdir    <br />    <br /> cacheManagerEventListenerFactory :指定CacheManagerEventListenerFactory,用于创建CacheManagerPeerProvider    <br />    <br /> 用于提醒当CacheManager中的缓存增加或者删除时。    <br />        <br />     属性:class:完整的工厂类名称    <br />          properties:逗号分割的属性    <br />    <br /> 事件包括 增加cache和删除cache    <br />    <br /> cacheManagerPeerProviderFactory:指定CacheManagerPeerProviderFactory,用于创建CacheManagerPeerProvider,用于在cluster中查找CacheManagers,主要用于机群环境    <br />    <br />     属性:    <br />         class:完整的工厂类名称    <br />         properties:逗号分割的属性    <br />    <br /> 默认的配置:    <br />      <br />    <pre class="brush:xml; toolbar: true; auto-links: false;"><cacheManagerPeerProviderFactory                                 class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"                                 properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,                                     multicastGroupPort=4446, timeToLive=32"/></pre>    <br />    <pre class="brush:xml; toolbar: true; auto-links: false;"><cacheManagerPeerProviderFactory class=                           "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"                           properties="peerDiscovery=manual,                           rmiUrls=//server1:40000/sampleCache1|//server2:40000/sampleCache1                           | //server1:40000/sampleCache2|//server2:40000/sampleCache2"/>  </pre>      <br />    <br /> cacheManagerPeerListenerFactory:指定CacheManagerPeerListenerFactory,用于创建CacheManagerPeerListener,监听cluster中的复制信息    <br />     属性:    <br />         class:完整的工厂类名称    <br />         properties:逗号分割的属性    <br />    <br /> 默认配置    <br />      <br />    <pre class="brush:xml; toolbar: true; auto-links: false;">    <cacheManagerPeerListenerFactory         class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"         properties="hostName=fully_qualified_hostname_or_ip,                     port=40001,                     socketTimeoutMillis=120000"/>     </pre>    <br />    <br /> defaultCache: 默认缓存配置    <br />    <br />     必须属性:    <br />         name:设置缓存的名称,用于标志缓存,惟一    <br />         maxElementsInMemory:在内存中最大的对象数量    <br />         maxElementsOnDisk:在DiskStore中的最大对象数量,如为0,则没有限制    <br />         eternal:设置元素是否永久的,如果为永久,则timeout忽略    <br />         overflowToDisk:是否当memory中的数量达到限制后,保存到Disk    <br />    <br />     可选的属性:    <br />         timeToIdleSeconds:设置元素过期前的空闲时间    <br />         timeToLiveSeconds:设置元素过期前的活动时间    <br />         diskPersistent:是否disk store在虚拟机启动时持久化。默认为false    <br />         diskExpiryThreadIntervalSeconds:运行disk终结线程的时间,默认为120秒    <br />         memoryStoreEvictionPolicy:策略关于Eviction    <br />    <br /> 缓存子元素:    <br />        <br />     cacheEventListenerFactory:注册相应的的缓存监听类,用于处理缓存事件,如put,remove,update,和expire    <br />     bootstrapCacheLoaderFactory:指定相应的BootstrapCacheLoader,用于在初始化缓存,以及自动设置。    <br /> 如下的例子:    <br />      <br />    <pre class="brush:xml; toolbar: true; auto-links: false;"> <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"          properties="replicateAsynchronously=true,          replicatePuts=true,          replicateUpdates=true,          replicateUpdatesViaCopy=true,          replicateRemovals=true "/>        <bootstrapCacheLoaderFactory         class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"         properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"/>         <defaultCache             maxElementsInMemory="10000"             eternal="false"             timeToIdleSeconds="120"             timeToLiveSeconds="120"             overflowToDisk="true"             maxElementsOnDisk="10000000"             diskPersistent="false"             diskExpiryThreadIntervalSeconds="120"             memoryStoreEvictionPolicy="LRU"             />     </pre>    <br />    <br /> cache配置同defaultCache    <br />      <br />    <pre class="brush:xml; toolbar: true; auto-links: false;"><cache name="sampleDistributedCache1"            maxElementsInMemory="10"            eternal="false"            timeToIdleSeconds="100"            timeToLiveSeconds="100"            overflowToDisk="false">         <cacheEventListenerFactory                 class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>         <bootstrapCacheLoaderFactory                 class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>     </cache>     </pre>    <br /> 基本上都比较简单,当然也可以直接使用程序实现相应的功能    <br />