asdtiang的博客 感謝blogjava提供的博客交流平臺

          s2sh整合ehcache頁面部分緩存

          Posted on 2011-03-12 22:25 asdtiang 閱讀(708) 評論(0)  編輯  收藏

          首先看web.xml配置:

          增加以下配置:

          <!--ehcache web page cache -->
               
          <filter>
              
          <filter-name>fragmentCache</filter-name>
              
          <filter-class>net.sf.ehcache.constructs.web.filter.SimplePageFragmentCachingFilter
              
          </filter-class>
               
          <init-param>
                
          <param-name>suppressStackTraces</param-name>
                
          <param-value>false</param-value>
              
          </init-param>
              
          <init-param>
                
          <param-name>cacheName</param-name>
                
          <param-value>fragmentCache</param-value>
              
          </init-param>
              
            
          </filter>

              
          <!--
                  This is a filter chain. They are executed in the order below. Do not
                  change the order.
              
          -->

               
          <filter-mapping>
              
          <filter-name>fragmentCache</filter-name>
              
          <url-pattern>/WEB-INF/pages/tour/tourDetailBody.jsp</url-pattern>
              
          <dispatcher>INCLUDE</dispatcher> 
              
          </filter-mapping>


          注意,那個<dispatcher>INCLUDE</dispatcher>,不能少,少了緩存不能用。


          配置中對應(yīng)<jsp:include page="/WEB-INF/pages/tour/tourDetailBody.jsp"/>

          2.4版本的servlet規(guī)范在部屬描述符中新增加了一個<dispatcher>元素,這個元素有四個可能的值:即REQUEST,FORWARD,INCLUDE和ERROR,可以在一個<filter-mapping>元素中加入任意數(shù)目的<dispatcher>,使得filter將會作用于直接從客戶端過來的request,通過forward過來的request,通過include過來的request和通過<error-page>過來的request。如果沒有指定任何< dispatcher >元素,默認值是REQUEST。

           

          <?xml version="1.0" encoding="UTF-8"?>
          <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation
          ="../../main/config/ehcache.xsd">

              
          <diskStore path="java.io.tmpdir" />

              
          <defaultCache 
                  
          maxElementsInMemory="10" 
                  eternal
          ="false"
                  timeToIdleSeconds
          ="5" 
                  timeToLiveSeconds
          ="10" 
                  overflowToDisk
          ="true" />
              
          <!--
                  maxElementsInMemory="10"內(nèi)存中的最大頁面對象 
                  eternal="false"
                  timeToIdleSeconds="120" timeToIdleSeconds ,多長時間不訪問該緩存,那么ehcache就會清除該緩存。 
                  timeToLiveSeconds="240" timeToLiveSeconds,緩存的存活時間,從開始創(chuàng)建的時間算起。
                  overflowToDisk="true" 是否寫入硬盤
              
          -->
              
          <!-- Page and Page Fragment Caches -->

              
          <cache name="fragmentCache" 
                  maxElementsInMemory
          ="10" 
                  eternal
          ="false"
                  timeToIdleSeconds
          ="10000" 
                  timeToLiveSeconds
          ="10000" 
                  overflowToDisk
          ="true">
              
          </cache>
          </ehcache>


          數(shù)據(jù)的更新問題:

          和頁面緩存一樣的,根據(jù)配置文件中的cacheName獲取Ehcache,再根據(jù)獲取的key進行remove操作。

          action中的問題:當(dāng)頁面請求發(fā)生時,會調(diào)用action方法,這時我們因為先方法,應(yīng)該先查詢cache中是否有緩存fragment存在,如果有,直接返回成功頁面,如果沒有則執(zhí)行剩下的代




          天蒼蒼,野茫茫,風(fēng)吹草底見牛羊

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           

          posts - 80, comments - 24, trackbacks - 0, articles - 32

          Copyright © asdtiang

          asdtiang的博客 PaidMailz
          點擊廣告網(wǎng)賺A(每天4個廣告,每個0.0025美元,一個搜索廣告0.03美元)
          主站蜘蛛池模板: 和田市| 孝义市| 汝阳县| 卓尼县| 高阳县| 汉中市| 大渡口区| 常山县| 奎屯市| 山东省| 利津县| 德江县| 文化| 阿巴嘎旗| 台前县| 德钦县| 额敏县| 旬阳县| 都安| 杭锦旗| 化德县| 庆阳市| 柞水县| 邻水| 岱山县| 吉木萨尔县| 登封市| 芦溪县| 兴和县| 甘孜县| 大同市| 商城县| 香格里拉县| 尚志市| 桃源县| 留坝县| 康保县| 兰溪市| 铅山县| 崇明县| 盐源县|