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 >元素,默認(rèn)值是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進(jìn)行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
          點(diǎn)擊廣告網(wǎng)賺A(每天4個廣告,每個0.0025美元,一個搜索廣告0.03美元)
          主站蜘蛛池模板: 东光县| 新沂市| 东城区| 神木县| 阿拉尔市| 泰来县| 贺兰县| 天台县| 通榆县| 井陉县| 海阳市| 贵溪市| 浦北县| 舞阳县| 万山特区| 绥德县| 紫阳县| 涿鹿县| 岫岩| 台北市| 南皮县| 库车县| 永胜县| 禹城市| 阿拉善右旗| 灵山县| 平泉县| 芒康县| 海安县| 栖霞市| 崇信县| 吉安县| 凌海市| 常宁市| 威宁| 芜湖县| 阳谷县| 阳山县| 德阳市| 福泉市| 攀枝花市|