1.导入相应jar包:

  

2.在jsp页面引入oscache指令

<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="oscache" %>

3.jsp小案例

   <%=new SimpleDateFormat("yyyy-MM-dd:hh-mm-ss").format(new Date())%><br/>
    <oscache:cache time="2" scope="session" key="">
    <%=new SimpleDateFormat("yyyy-MM-dd:hh-mm-ss").format(new Date())%><br/>
    </oscache:cache>

4.本地持久化缓存文件

  在classpath下新建oscache.properties,内容如下:

cache.memory=false
cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
cache.path=F:\\cache

 

  

4.参数说明:

  scope:指定缓存存放的域,可以是session or application

  time:指定缓存的有效时长,单位second

  key:标识缓存内容的关键词。在指定的作用范围内必须是唯一的。默认的key是被访问页面的URI和后面的请求字符串,因为缓存的设计结构是map类型

5.for more message ask for :https://www.cnblogs.com/austinspark-jessylu/p/6138265.html