oscache缓存jsp页面

一.介绍
1.作用:oscache用来缓存jsp页面的
2.缓存数据结构:用map实现的,key存储浏览器访问url,value存储内容,如果访问2个url不一致,缓存肯定变化。

二.导包
oscache-2.4.1.jar,commons-logging-1.2.jar

三.示例
1.创建一个index.jsp页面,使用时间来测试
index.jsp

<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!-- 导入标签 -->
<%@taglib prefix="o" uri="http://www.opensymphony.com/oscache" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
    现在时间:<%=new Date()%><br>
    <!--
      把想缓存的内容放入 o:cache标签中

      缓存的作用域:缓存默认存储在application域当中,可更改缓存作用域。
      通过 scope="session 将缓存作用域改成session

      缓存刷新时间
      time="4" 4秒刷新缓存

      缓存持久化
      创建oscache.properties这个配置文件必须在classpath下面:
    -->
    <o:cache scope="session" time="4">
      现在缓存:<%=new Date()%>
    </o:cache>
  </body>
</html>

四.oscache整合ssm项目
在web.xml中配置页面缓存

<!-- 配置oscache缓存jsp -->
    <filter>
        <filter-name>oscache</filter-name>
        <filter-class>com.opensymphony.oscache.web.filter.CacheFilter</filter-class>
        <init-param>
            <param-name>time</param-name>
            <!--缓存刷新时间-->
            <param-value>3600</param-value>
        </init-param>
        <init-param>
            <param-name>scope</param-name>
            <!--缓存作用域 application或session-->
            <param-value>application</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>oscache</filter-name>
        <!--作用url路径-->
        <url-pattern>/items/*</url-pattern>
    </filter-mapping>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值