ehcache缓存共享(rmi方法)

最近学了个新的东西; 别人的博客,而后作出了两个tomcat能共享缓存的ehcache.地址为:http://blog.csdn.net/wangshijie1234567/article/details/47724853java

下面是本身的实际文件内容缓存

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
         name="hibernate">
    <!-- xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" -->


    <diskStore path="java.io.tmpdir"/>

    <cacheManagerPeerProviderFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
            properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
         multicastGroupPort=4446,
         timeToLive=32"
    />
<!--multicastGroupAddress 邮件组的地址,不需修改-->
<!--multicastGroupPort 邮件组的端口-->
<!--timeToLive 心跳时间-->

    <cacheManagerPeerListenerFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
            properties="hostName=192.168.0.119, port=40001,
       socketTimeoutMillis=2000"/>
<!--hostName不能为127.0.0.1,也不能是localhost-->
<!-- 注册时,不一样项目的port必定不一样-->

    <defaultCache eternal="false" maxElementsInMemory="1000" overflowToDisk="false" diskPersistent="false"
                  timeToIdleSeconds="0" timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU">
        <cacheEventListenerFactory
                class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>
    </defaultCache>

    <!--
        name: Cache的惟一标识。
        maxElementsInMemory: 内存中最大缓存对象数。
        eternal="true": Element是否永久有效,一旦设置true,timeout将不起做用
        timeToIdleSeconds: 设置Element在失效前的容许闲置时间。仅当element不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大。
        timeToLiveSeconds: 设置Element在失效前容许存活时间。最大时间介于建立时间和失效时间之间。仅当element不是永久有效时使用,默认是0.,
        也就是element存活时间无穷大。
        overflowToDisk: 配置此属性,当内存中Element数量达到maxElementsInMemory时,Ehcache将会Element写到磁盘中。
    -->

</ehcache>

timeToLive的值指的是数据包能够传递的域或是范围。约定以下:tomcat

  • 0是限制在同一台主机
  • 1是限制在同一个子网
  • 32是限制在同一个场所
  • 64是限制在同一个地区
  • 128是限制在同一个大洲
  • 255是不限制

在Java实现中默认值是1,就是说在同一个子网中传播。改变超时时间也就是改变timeToLive属性能够限制或是扩展传播的范围。socket

相关文章
相关标签/搜索