关于缓存框架oscache的几点总结

1 oscache环境搭建网上介绍很多,但是基本上都会抛出异常,从官网上找了个例子才跑通

2 配置不算复杂,需要2个包 (第一个和第三个包必备)

   

3 导入的配置文件

 不可或缺

4 进行页面拦截的配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>oscache</display-name>
  <!----><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>session</param-value>
    </init-param>
         <init-param>
         <param-name>oscache-properties-file</param-name>
         <param-value>/oscache-cachefilter-disableCacheOnMethods.properties</param-value>
     </init-param>
    
  </filter>
  <filter-mapping>
    <filter-name>CacheFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
  </filter-mapping>  
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>DataServlet</display-name>
    <servlet-name>DataServlet</servlet-name>
    <servlet-class>com.oscache.servlet.DataServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>DataServlet</servlet-name>
    <url-pattern>/DataServlet</url-pattern>
  </servlet-mapping>
</web-app>

注意:
有的web.xml里面加了

	<listener>
        <listener-class>com.opensymphony.oscache.web.CacheContextListener</listener-class>
    </listener>

但是测试过,加不加都可以的,这个以后待定。



5 主jsp页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*;" %>
<%@ taglib uri="/WEB-INF/classes/oscache.tld" prefix="oscache"%>    
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>


<%=new Date() %><br>

<oscache:cache time="30">
	time:<%=new Date() %>
</oscache:cache>

	<form method="post" action="DataServlet">
		<input type="submit" value="提交">
	</form>
	<oscache:cache time="8" key="">
	<c:forEach var="li" items="${sessionScope.list}">
		${li};
	</c:forEach><br>
	</oscache:cache>
	
	<oscache:cache key="foobar" scope="session">
	key[理解为可变]:<%=new Date() %>
	</oscache:cache><br>
	
	<oscache:cache duration="3">
		duration:<%=new Date() %>
	</oscache:cache><br>
	
	<!-- 就是让功能失效,不走这块代码 -->
	<oscache:cache mode="silent">
	mode:<%=new Date() %>
	</oscache:cache>
</body>
</html>

6 比较神奇的地方 如果过滤*.jsp 只对jsp页面拦截,配置 *则对所有请求拦截

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

静山晚风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值