OSCache 的緩衝技術在JSP頁面中的使用

來源:互聯網
上載者:User
 http://www.opensymphony.com/oscache/ 
2 把下載的jar 加入到你的build path 裡面。 建議直接放到 tomcat/shared/lib 目錄下面
3 在 web.xml 裡面增加配置

        <taglib>
                <taglib-uri>oscache</taglib-uri>
                <taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>
        </taglib>

4 在你的jsp 頁面裡增加如下標籤

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

5 在需要緩衝的部分,採用如下標籤

<cache:cache key="myPageCachekey" groups="myDefaultGroup" scope="application" time="1800">
。。。 這中間是你要緩衝的內容
</cache:cache>

6 重新整理緩衝

<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.
    傳遞給重新整理策略類的參數

 原始地址:http://www.java2000.net/viewthread.jsp?tid=2944

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.