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美元)
          主站蜘蛛池模板: 如东县| 沈阳市| 高密市| 贵定县| 上饶市| 永靖县| 临西县| 马龙县| 红河县| 康马县| 高碑店市| 许昌县| 宜丰县| 通化市| 平果县| 会昌县| 敦煌市| 江孜县| 遂宁市| 哈尔滨市| 石柱| 广元市| 柳林县| 板桥市| 田阳县| 石景山区| 宜州市| 红桥区| 枞阳县| 景泰县| 奉新县| 从化市| 乐都县| 财经| 临猗县| 襄汾县| 磐石市| 调兵山市| 苍溪县| 昌邑市| 厦门市|