http://www.opensymphony.com/oscache/
jsp页面代码引用
<%@ tablib uri="oscache" prefix="os"%>
1-----------<cache></cache>
<os:cache key="key1" time="1800" refresh="true">
<!--这是要缓存的内容,缓存保持30分钟,到期自动刷新-->
</os>
<os:cache key="key2" cron="0 2 * * * " refresh="true">
<!-- 这是要缓存的内容,缓存内容在每天凌晨2点自动刷新-->
</os>
2---------------------<usecached/>
<os:cache>
.....内容1.....
<%try{%>
.....内容2.....
<%}catch(Exception e){%>
catch:<os:usecached use="true"/>YES
<%}%>
如果use为true出现异常时候会输出“Missing cached content”如为false
则 .....内容1.....
.....内容2.....
cache:YES
3-----------------<flush/>
运行状态下刷新缓存
<os:flush scope="application"/> 用来刷新整个application缓存
<os:flush scope="session" key="foobar"/> 用来刷新session中的foobar
<os:flush scope="application" group="currentData" /> 用来刷新application中currentData组中的缓存
4---------<addgroup/>
<os:cache key="key3">
<os:addgroup group="group1"/>
........内容1........
<os:addgroup group="group2"/>
..........内容2..........
</os:cache> 把key3加入到group1和group2
5--------------------------<addgroups/>
<os:cache key="key3">
...............内容1.......................
<os:addgroups groups="group1,group2"/>
..................内容2....................
</os:cache>
-----------------------------------------web.xml-------------------------------------------------
使用过滤器缓存整个页面
<filter>
<filter-name>CacheFilter</filter-name>
<filter_class>com.opensymphony.oscache.we.filter.CacheFilter</filter-class>
<init-param>
<param-name>time</param-name>
<param-value>600</param-value>
</init-param>
<init-param>
<param-name>sco</param-name>
<param-value>600</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CacheFilter</filter-name>
<url-pattern>*.jsp<url-pattern>
</filter-mapping>