<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    paulwong

    在jsp頁面中使用oscache標簽實現可配置的頁面緩存

    最近在學習oscache的相關內容,寫點東西作為鞏固

    如果在jsp中使用如下標簽

    <cache:cache key="foobar" scope="session">  
              some jsp content   
    </cache:cache> 


    那么這中間的一段jsp代碼將會以key="foobar"緩存在session中,任何其他頁面中使用這個key
    的cache標簽都能共享這段存在緩存中的執(zhí)行結果

    考慮一個需求,一個頁面是有許多個不同的jsp文件拼出來的
    可能在頁首有隨機的廣告,登錄用戶的信息,系統的即時信息,固定的目錄信息等等
    這其中可以考慮將固定的目錄信息放入緩存中,而其他動態(tài)信息則即時刷新
    再進一步考慮 有時候頁面之間的信息是關聯的,只有當其中一條信息的內容變化了才需要去刷新
    對于這種需求就可以考慮在<cache:cache/>標簽中配置group屬性,將不同的具有關聯關系的cache內容
    分組,這樣oscache會自動的幫你檢查該組緩存內容的變化情況,如果有任何一子成員組的內容變化了
    則會執(zhí)行刷新,這樣就可以在頁面實現數據的動態(tài)同步
    代碼如下:(來源oscache:groupTest.jsp )



    <%@ page import="java.util.*" %>  
    <%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>  
       
     
    <head>  
     
    <title>Test Page</title>  
     
    <style type="text/css">  
     body 
    {font-family: Arial, Verdana, Geneva, Helvetica, sans-serif}  
     
    </style>  
     
    </head>  
     
    <body>  
       
     
    <href="<%= request.getContextPath() %>/">Back to index</a><p>  
     
    <hr>Flushing 'group2'<hr>  
     
    <cache:flush group='group2' scope='application'/>  
     
    <hr>  
     
    <cache:cache key='test1' groups='group1,group2' duration='5s'>  
         
    <b>Cache Time</b><%= (new Date()).getTime() %><br>  
         This is some cache content test1 that is in 'group1' and 'group2'. Normally it would refresh if it  
         was more than 5 seconds old, however the 
    <cache:flush group='group2' scope='application'>  
         tag causes this entry to be flushed on every page refresh.
    <br>  
     
    </cache:cache>  
     
    <hr> 



    這里有兩個cache分組group1和group2,將group2設置為每次都執(zhí)行刷新,所以test1為key的cache每次刷新頁面內容都是重新執(zhí)行過的

    <cache:cache key='test2' groups='group1' duration='5s'>  
        
    <b>Cache Time</b><%= (new Date()).getTime() %><br>  
         This is some cache content test2 that is in 'group1' (refreshes if more than 5 seconds old)
    <br>  
     
    </cache:cache>  
     
    <hr> 


    而test2只有當間隔時間超過5秒才會更新內容

     <cache:cache key='test3' duration='20s'>  
         
    <b>Cache Time</b><%= (new Date()).getTime() %><br>  
         This is some cache content test3 that is in 'group1' and 'group2'. The groups are added using the 
    <cache:addgroup /> tag.<br>  
         
    <cache:addgroup group='group1'/>  
         
    <cache:addgroup group='group2'/>  
     
    </cache:cache>  
     
    <hr>  
     
    <cache:cache key='test4' duration='20s'>  
         
    <b>Cache Time</b><%= (new Date()).getTime() %><br>  
         This is some cache content test4 that is in 'group1' and 'group2'. The groups are added using the 
    <cache:addgroups /> tag.<br>  
         
    <cache:addgroups groups='group1,group2'/>  
    </cache:cache>  
     
    <hr>  
     
    </body>  
    </html> 


    <cache:addgroup group='{you_group}'/>可以將所在的cache加入存在的group中

    posted on 2008-02-19 22:28 paulwong 閱讀(1499) 評論(0)  編輯  收藏 所屬分類: J2EE

    主站蜘蛛池模板: 18禁止看的免费污网站| 国产美女被遭强高潮免费网站| 95老司机免费福利| 国产精品久久久亚洲| 国产免费网站看v片在线| 亚洲狠狠婷婷综合久久久久| 国产午夜成人免费看片无遮挡| 国产亚洲精品va在线| 永久在线观看免费视频| 自怕偷自怕亚洲精品| 最新黄色免费网站| 亚洲AV无码乱码麻豆精品国产| 一二三四视频在线观看中文版免费 | 国产在线jyzzjyzz免费麻豆| 国产成人亚洲精品影院| 中文成人久久久久影院免费观看 | 精品久久久久成人码免费动漫| 77777午夜亚洲| 麻豆国产入口在线观看免费| 一级视频免费观看| 亚洲AV无码1区2区久久| 成年女人免费视频播放体验区 | 亚洲人成未满十八禁网站 | 亚洲avav天堂av在线不卡| 亚洲w码欧洲s码免费| 日本亚洲中午字幕乱码| 男男AV纯肉无码免费播放无码 | 久久精品无码专区免费青青| 亚洲日韩国产精品乱-久| 久久久久久影院久久久久免费精品国产小说 | 亚洲国产成人久久综合碰| 亚洲另类无码一区二区三区| 日本免费人成视频播放 | 国产午夜亚洲精品| 亚洲中文无韩国r级电影| 8x8x华人永久免费视频| 亚洲AV成人无码网站| 亚洲激情中文字幕| 免费观看四虎精品国产永久| 久久精品中文字幕免费| 亚洲AV成人精品网站在线播放|