<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標簽都能共享這段存在緩存中的執行結果

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

    <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

    主站蜘蛛池模板: 久久久久亚洲AV成人无码| www一区二区www免费| 在线播放亚洲精品| 13小箩利洗澡无码视频网站免费| 亚洲视频在线观看免费| 日韩免费三级电影| 亚洲av无码精品网站| 亚洲日本天堂在线| 日韩电影免费在线观看| 成年人视频在线观看免费| 亚洲人成人77777网站| 亚洲国产成人精品激情| a国产成人免费视频| 啦啦啦在线免费视频| 久久久久久a亚洲欧洲AV| 国产成人久久精品亚洲小说| 5g影院5g天天爽永久免费影院| 免费h黄肉动漫在线观看| 亚洲精品不卡视频| 在线观看人成视频免费无遮挡| 成人免费视频试看120秒| 久久亚洲中文字幕精品有坂深雪| 美女免费精品高清毛片在线视| 国产精品视频免费观看| 国产亚洲精品精华液| 美女露100%胸无遮挡免费观看| 18禁超污无遮挡无码免费网站国产| 亚洲AV无码第一区二区三区 | 亚洲卡一卡二卡乱码新区| 嫩草在线视频www免费观看| 亚洲AV无码乱码在线观看性色扶 | 亚洲精品国产日韩无码AV永久免费网 | 美女网站免费福利视频| 久久久久无码精品亚洲日韩| japanese色国产在线看免费| 成人免费视频国产| 亚洲日本VA中文字幕久久道具| 6080午夜一级毛片免费看6080夜福利| 国产国拍亚洲精品mv在线观看| 国产精品玖玖美女张开腿让男人桶爽免费看 | 久久国产精品国产自线拍免费|