OScache缓存

oScache是一个高性能的J2EE缓存框架,缓存部分JSP或HTTP请求,任何Java对象都可以缓存

缓存以kay value 方式来存储

也可以永久缓存:缓存可以随意写入磁盘     支持集群


使用OScache :

1.把所需jar拷贝lib(oscache-2.4.1.jar,jgroups-all.jar,commons-logging.jar

2.把oscache安装目录下oscache.properties放入src目录下

3.引入 <%@taglib prefix="oscache" uri="http://www.opensymphony.com/oscache" %>


4.页面添加缓存:

    当前时间:<%=new Date() %><br/>

    <oscache:cache time="10">页面缓存10秒钟

    缓存时间:<%=new Date() %>

    </oscache:cache>


    key:http://localhost:8080/oscache/index.jsp?id=2

    value:index.jsp


    缓存key将以请求的URL+查询字符串组成

    缓存默认存放在application范围,缓存时间默认为3600秒     1个小时


    确定:数据更新不及时

    

    <oscache:cache key="name"></oscache:cache>

    不再以URL+查询字符串组成


    <oscache:cache key="name" scope="session" time="10">

 scope="session" :不管页面的ID怎么编,缓存不变

    

5.web配置全局缓存配置:

<filter>

          <filter-name>CacheFilter</filter-name>

          <filter-class>com.opensymphony.oscache.web.filter.CacheFilter</filter-class>

          <init-param>

              <param-name>time</param-name>

              <param-value>5</param-value>

          </init-param>

          <init-param>

              <param-name>scope</param-name>

              <param-value>application</param-value>

          </init-param>

  </filter>

  <filter-mapping>

      <filter-name>CacheFilter</filter-name>

      <url-pattern>*.jsp</url-pattern>

  </filter-mapping>


6.Oscache配置属性介绍(oscache.properties)

指定缓存的容量:cache.capacity=1000

是否使用内存缓存,默认为true,cache.memory=false

如果指定硬盘缓存:cache.path=d:\\oscache


cache.capacity=1000

cache.memory=false

cache.path=d:\\oscache

cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener




你可能感兴趣的:(OScache缓存)