zoukankan      html  css  js  c++  java
  • Ehcache 使用

    自从Ehcache 到了1.2+的版本,就支持分布式缓存了

    Spring + Hibernate的结构 ,ehcache的对这几个框架的支持较好,就采用这个缓存方案

    下面是配置文件:

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

    <defaultCache maxElementsInMemory="10000"       eternal="false"    timeToIdleSeconds="120"    timeToLiveSeconds="120"    overflowToDisk="true"    maxElementsOnDisk="10000000"    diskPersistent="false"    diskExpiryThreadIntervalSeconds="120"    memoryStoreEvictionPolicy="LRU" >    </defaultCache> <cache name="smapCache"       maxElementsInMemory="10000"       eternal="false"    timeToIdleSeconds="3600"    timeToLiveSeconds="3600"    overflowToDisk="true"    maxElementsOnDisk="10000000"    diskPersistent="false"    diskExpiryThreadIntervalSeconds="120"    memoryStoreEvictionPolicy="LRU">     </cache>

    </ehcache>

    下面是分布式缓存配置

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

    <!--自动查找局域网中分布式的peer 。也可手工指定节点的地址的,如:peerDiscovery=manual,rmiUrls=//server1:40000/sampleCache1 --> <cacheManagerPeerProviderFactory    class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"    properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446" />

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

    <defaultCache maxElementsInMemory="10000"       eternal="false"    timeToIdleSeconds="120"    timeToLiveSeconds="120"    overflowToDisk="true"    maxElementsOnDisk="10000000"    diskPersistent="false"    diskExpiryThreadIntervalSeconds="120"    memoryStoreEvictionPolicy="LRU" >    </defaultCache> <cache name="smapCache"       maxElementsInMemory="10000"       eternal="false"    timeToIdleSeconds="3600"    timeToLiveSeconds="3600"    overflowToDisk="true"    maxElementsOnDisk="10000000"    diskPersistent="false"    diskExpiryThreadIntervalSeconds="120"    memoryStoreEvictionPolicy="LRU">   <cacheEventListenerFactory          class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>    </cache>

    </ehcache>

    必须属性: name:设置缓存的名称,用于标志缓存,惟一 maxElementsInMemory:在内存中最大的对象数量 maxElementsOnDisk:在DiskStore中的最大对象数量,如为0,则没有限制 eternal:设置元素是否永久的,如果为永久,则timeout忽略 overflowToDisk:是否当memory中的数量达到限制后,保存到Disk

    可选的属性: timeToIdleSeconds:设置元素过期前的空闲时间 timeToLiveSeconds:设置元素过期前的活动时间 diskPersistent:是否disk store在虚拟机启动时持久化。默认为false diskExpiryThreadIntervalSeconds:运行disk终结线程的时间,默认为120秒 memoryStoreEvictionPolicy:策略关于Eviction

    缓存子元素: cacheEventListenerFactory:注册相应的的缓存监听类,用于处理缓存事件,如put,remove,update,和expire bootstrapCacheLoaderFactory:指定相应的BootstrapCacheLoader,用于在初始化缓存,以及自动设置。

    spring配置:

         <!-- ehcache --> <bean id="cacheManager"          class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">          <property name="configLocation"              value="classpath:ehcache.xml">          </property>      </bean>

         <bean id="smapCacheBean" class="org.springframework.cache.ehcache.EhCacheFactoryBean">          <property name="cacheManager" ref="cacheManager"></property>          <property name="cacheName" value="smapCache"></property>      </bean>

  • 相关阅读:
    《挑战30天C++入门极限》新手入门:关于C++中的内联函数(inline)
    《挑战30天C++入门极限》新手入门:C/C++中枚举类型(enum)
    《挑战30天C++入门极限》新手入门:C++中布尔类型
    《挑战30天C++入门极限》新手入门:C++下的引用类型
    《挑战30天C++入门极限》新手入门:C/C++中数组和指针类型的关系

    《挑战30天C++入门极限》入门教程:C++中的const限定修饰符
    《挑战30天C++入门极限》c++中指针学习的两个绝好例子
    《挑战30天C++入门极限》在c/c++中利用数组名作为函数参数传递排序和用指针进行排序的例子。
    《挑战30天C++入门极限》引言
  • 原文地址:https://www.cnblogs.com/jirglt/p/3780175.html
Copyright © 2011-2022 走看看