OSCache 的JSP页面缓冲技术

1 下载地址 http://www.opensymphony.com/oscache/
2 把下载的jar 加入到你的build path 里面。 建议直接放到 tomcat/shared/lib 目录下面
3 在 web.xml 里面增加配置
  1. <taglib>   
  2.         <taglib-uri>oscache</taglib-uri>   
  3.         <taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>   
  4. </taglib>  
        <taglib>
                <taglib-uri>oscache</taglib-uri>
                <taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>
        </taglib>


4 在你的jsp 页面里增加如下标签
  1. <%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache"%>  
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache"%>


5 在需要缓冲的部分,采用如下标签

  1.     
  2. <cache:cache key="myPageCachekey" groups="myDefaultGroup" scope="application" time="1800">   
  3. 。。。 这中间是你要缓冲的内容   
  4. </cache:cache>  
 
<cache:cache key="myPageCachekey" groups="myDefaultGroup" scope="application" time="1800">
。。。 这中间是你要缓冲的内容
</cache:cache>


6 刷新缓冲
  1. <cache:flush scope="application" group="myDefaultGroup" />  
<cache:flush scope="application" group="myDefaultGroup" />



其中的
key - [默认为请求的 request URI + query string] -
The cache key, any string. This should be unique for the given scope since duplicate keys will map to the same cache entry. The default value uses an escaped version of the URI and query string of the current page.
It is possible to specify multiple cache tags in the same page without specifying keys - in this situation an index is appended to the key of subsequent tags. However this usage is discouraged since if the flow of the page is inconsistent, or cache tags are nested, the indicies will potentially change each time the page is executed, resulting in seemingly jumbled cache entries.
缓冲的key,可以是任何的字符串。在一个范围内是唯一的,因为相同的key代表了相同的缓冲入口。默认使用请求的URI和请求的字符串(问号后面的部分)

scope - [application] - The scope of this cache (valid values are "application" and "session").
范围,有application和session, 默认为 application

time - [3600] The amount of time to cache this content for (in seconds). (Default is 3600 seconds, one hour). Supplying a negative value for this attribute means that the content never expires.
缓冲内容的时间(秒)。默认为1小时,3600秒,如果为-1则内容你永远不过期


duration - [] - The duration of this cache (this attribute is an alternative to time). duration can be specified using Simple Date Format or ISO-8601 date format.
另外一种设置缓冲时间的方法。可以用简单日期格式或者ISO-8601的日期格式

cron - [] - A cron expression that determines when this cached content will expire. This allows content to be expired at particular dates and/or times, rather than once a cache entry reaches a certain age. See Cron Expressions to read more about this attribute.
定时刷新的设置。可以在指定的时间和周期进行刷新。

refresh - [false] - A boolean. If true, the cache will be refreshed regardless of whether it is considered stale or not. This enables you to decide at runtime whether or not to rebuild the content.
强制刷新缓冲


mode - [] - Setting this to "silent" will prevent the body of the tag from being written to the output stream. This may be useful if you want to preload the cache with content without actually displaying that content to the user.
设置为[silent]可以让你提前把内容读取,但不会输出到。


groups - [] - A comma-delimited list of group names can be provided. This allows cache entries to be grouped according to your needs. Grouping is useful when you have cached content that depends on other parts of your application or data - when that dependency changes, flushing the relevant group will cause all cache entries in that group to be expired.
设置分组。可以同组的缓冲数据进行控制,比如刷新


language - [] - The ISO-639 language code to distinguish different content cached under an otherwise identical key. This is useful on a multilingual site where the same JSP code is used to render content in different languages depending on the current user's preferences.
语言,我没用过,也没发现问题。 默认为当前页面的语言吧

refreshpolicyclass - [] - A fully-qualified classname that extends com.opensymphony.oscache.web.WebEntryRefreshPolicy. This allows you to programmatically determine whether cached content should be exipired.
自定义的刷新策略类。自己控制什么时候刷新数据


refreshpolicyparam - [] - Any arbitrary parameters that you need to pass through to the refreshpolicyclass. Specifying this attribute without specifying a refreshpolicyclass will have no effect.
传递给刷新策略类的参数
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值