`
y806839048
  • 浏览: 1072303 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

ehcache 应用

阅读更多
http://raychase.iteye.com/blog/1545906
http://www.cnblogs.com/hoojo/archive/2012/07/12/2587556.html

ehcach的应用可以启发web页面缓存,当然ehcach本身就有页面缓存 ehcache-web,缓存漂移(Cache Drift)
cacheManage ---manage --- Element(缓存的数据结构)


在web.xml中
<filter>
    <filter-name>gzipCachingFilter</filter-name>
    <filter-class>net.sf.ehcache.constructs.web.filter.GzipFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>gzipCachingFilter</filter-name>
    <url-pattern>*.js</url-pattern>
    <url-pattern>*.css</url-pattern>
  </filter-mapping>
在spring配置文件中

导入命名空间:

xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xmlns:p="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring 
    http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd

<!-- 自动扫描注解 -->
<ehcache:annotation-driven />
<!-- 缓存配置,如需要可以另加配置 -->
<ehcache:config cache-manager="cacheManager">
<ehcache:evict-expired-elements
interval="60" />
</ehcache:config>
<!-- 缓存管理器,指定ehcache的配置文件路径 -->
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>



========================ehcahe.xml===================================



<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">
<!--
maxElementsInMemory:缓存中允许创建的最大对象数
eternal:缓存中对象是否为永久的,如果是,超时设置将被忽略,对象从不过期。
timeToIdleSeconds:缓存数据的钝化时间,也就是在一个元素消亡之前, 两次访问时间的最大时间间隔值,这只能在元素不是永久驻留时有效, 如果该值是 0 就意味着元素可以停顿无穷长的时间。
timeToLiveSeconds:缓存数据的生存时间,也就是一个元素从构建到消亡的最大时间间隔值, 这只能在元素不是永久驻留时有效,如果该值是0就意味着元素可以停顿无穷长的时间。
overflowToDisk:内存不足时,是否启用磁盘缓存
memoryStoreEvictionPolicy:缓存满了之后的淘汰算法。
-->
<!--指定缓存文件目录 -->
<diskStore path="java.io.tmpdir" />
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" />
<cache name="eternalCache" eternal="true" maxElementsInMemory="10000" />
    <cache name="topoDataCache" eternal="false" timeToLiveSeconds="3600"  maxElementsInMemory="1000"/>
</ehcache>

=============================java中使用===============================



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics