OSCache页面缓存

    xiaoxiao2021-12-14  18

    ***页面缓存  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"/>application范围内缓存已清除  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.DiskPersisten

    转载请注明原文地址: https://ju.6miu.com/read-970222.html

    最新回复(0)