OScache

本文介绍了OpenSymphony的OSCache组件如何应用于JSP页面,实现页面内容的缓存功能。详细阐述了缓存标签的使用方法,包括设置缓存时间、自动刷新策略、异常处理及缓存清除等。此外,还提供了如何通过过滤器配置来实现整个页面的缓存。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值