一.介绍
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>