OSCache页面缓存

缓存技术有:页面缓存(View,html代码)缺点是不能做到实时更新,优点是比二级缓存性能更高;二级缓存(mode/业务层,domain对象)优点是实时更新 
缓存产品有:EHCahce、OSCache、JbossCache(分布式缓存) 

***页面缓存 
1、清除缓存: 

<!-- refresh为true将会导致缓存的内容过期而被清除,简单地说,该属性为true用于清除缓存 --> 
  <!-- <oscache:flush scope="application"/>清除application范围内的所有缓存; 
  <oscache:flush scope="session" key="huhui"/>清除session范围内的key为huhui的缓存 
  <oscache:flush scope="application" group="hu"/>清除application范围内组名为hu内的所有缓存 --> 
<%@ page language="java" pageEncoding="UTF-8"%> 
<%@taglib uri="http://www.opensymphony.com/oscache" prefix="oscache" %> 
<oscache:flush scope="applocation"/>缓存已清除 

2、局部缓存: 
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="oscache" %> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head> 
    <title>My JSP 'index.jsp' starting page</title> 
<meta http-equiv="pragma" content="no-cache"> 
<meta http-equiv="cache-control" content="no-cache"> 
<meta http-equiv="expires" content="0"> 
  </head> 
  
  <body><!-- 这是局部缓存 --> 
  <oscache:cache key="huhui" scope="session" time="15" refresh="${param.refresh }"> 
  <!-- 是使用Map对象来存储缓存的,默认的key是uri路径,如:/oscache/index.jsp,也可以指定它的key --> 
  <!-- 缓存默认存放在application范围,缓存时间默认为3600秒,即1小时 --> 
    <div><%=new Date() %></div> 
  </oscache:cache> 
  当前时间:<%=new Date() %> 
  </body> 
</html> 

3、全局缓存:web.xml 
<!-- 设置页面的全局缓存 --> 
  <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>/product/list.do</url-pattern> 
   </filter-mapping> 

4、内存缓存/硬盘缓存(推荐使用内存缓存,比硬盘缓存要快得多)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实现页面缓存 http://javahuhui.iteye.com/blog/1481686

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值