OSCache页面缓存

简述

       高性能的J2EE缓存框架,主要是对页面的缓存,可以整页或者指定网页某一部分缓存,同时指定他的过期时间。

       特点:能永久缓存写入磁盘、缓存任何Java对象 JSP页面 HTTP请求、支持集群、控制缓存过期时间。


使用

       oscache 下载地址 http://www.opensymphony.com/oscache/download.action 

       需要的jar包有:oscache.jar、commons-logging.jar 
       需要将oscache.properties放在src下面.


全局缓存

<!-- 设置页面的全局缓存 --> 
<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>7200</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>/productst.do</url-pattern> 
</filter-mapping> 


局部缓存

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

<!--缓存默认存放在application范围,缓存时间默认为3600秒,即1小时。--> 

 <body>

        <oscache:cache key="huhui" scope="session" time="15" refresh="${param.refresh }"> 
        <!-- 是使用Map对象来存储缓存的,默认的key是uri路径,如:/oscache/index.jsp,也可以指定它的key --> 
          <div><%=new Date() %></div> 
        </oscache:cache> 


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


内存缓存/硬盘缓存(推荐使用内存缓存,比硬盘缓存要快得多)oscache.properties 

#指定是否使用内存缓存,默认值为true,即使用内存缓存 
cache.memory=true 

#指定缓存的容量,默认的容量是无限的 
cache.capacity=30000 
#如果要使用硬盘缓存,可以这样设置: 
cache.memory=false 

#指定缓存保存的路径 
cache.path=E:\\oscache

#用于设置持久化的类
cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener 


清除缓存

<oscache:flush scope="application"/>                        清除application范围内的所有缓存

<oscache:flush scope="session" key="huhui"/>         清除session范围内的key为huhui的缓存 

<oscache:flush scope="application" group="hu"/>    清除application范围内组名为hu内的所有缓存

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值