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

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

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

    隨筆 - 115  文章 - 481  trackbacks - 0
    <2007年11月>
    28293031123
    45678910
    11121314151617
    18192021222324
    2526272829301
    2345678

    常用鏈接

    留言簿(19)

    隨筆檔案(115)

    文章檔案(4)

    新聞檔案(1)

    成員連接

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    總體思路:使用Hibernate3.2的二級緩存,解決使用頻率最多的find(Class clz,Object id)方法的緩存。

    一、使用Hibernate3.2的二級緩存功能,只開取針對id查找實體的緩存,不開啟基于list查詢的緩存。
    技術調整如下:
    1、升級Spring2的版本號,升級為2.06,更新spring.jar、spring-aspects.jar、spring-mock.jar,為了使用spring modules中提供的cache功能,增加了spring-modules-cache.jar。以上包已經添加到svn中。

    2、修改jpa-base.xml中的entityManagerFactory Bean的配置信息,把對loadTimeWeaver屬性的注入注釋掉。

    <BEAN class=org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean name="entityManagerFactory"></BEAN>  
      
    <property name="persistenceXmlLocation" value="classpath:persistence.xml"></property>  
      
    <property name="dataSource" ref="dataSource"></property>  
      
    <property name="jpaVendorAdapter">  
       
    <BEAN class=org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter></BEAN>  
        
    <property name="database" value="MYSQL"></property>  
        
    <property name="showSql" value="false"></property>  
        
    <property name="generateDdl" value="false"></property>  
     
      
    </property>  
      
    <!--   
      <property name="loadTimeWeaver">  
       <bean  
        class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />  
      </property>
    -->  


    在persistence.xml文件中,添加如下的配置信息,開啟Hibernate的二級緩存: 

    <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"></property>  
    <property name="hibernate.cache.use_query_cache" value="false"></property><!--暫時不開query cache-->

    3、在src目錄下增加ehcache.xml,設置cache的配置信息,默認情況下可以考慮給一些常用的Entity類設置一個單獨的cache區域,如下所示:

    <CACHE name="com.easyjf.security.Resource" maxelementsinmemory="1000" eternal="false" overflowtodisk="false" memorystoreevictionpolicy="LFU"></CACHE>  
    <!--配置信息的說明如下:   
    缺省緩存配置。CacheManager 會把這些配置應用到程序中。   
            下列屬性是 defaultCache 必須的:   
      
            maxInMemory           - 設定內存中創建對象的最大值。   
            eternal                        - 設置元素(譯注:內存中對象)是否永久駐留。如果是,將忽略超   
                                                  時限制且元素永不消亡。   
            timeToIdleSeconds  - 設置某個元素消亡前的停頓時間。   
                                                  也就是在一個元素消亡之前,兩次訪問時間的最大時間間隔值。   
                                                  這只能在元素不是永久駐留時有效(譯注:如果對象永恒不滅,則   
                                                  設置該屬性也無用)。   
                                                  如果該值是 0 就意味著元素可以停頓無窮長的時間。   
            timeToLiveSeconds - 為元素設置消亡前的生存時間。   
                                                   也就是一個元素從構建到消亡的最大時間間隔值。   
                                                   這只能在元素不是永久駐留時有效。   
            overflowToDisk        - 設置當內存中緩存達到 maxInMemory 限制時元素是否可寫到磁盤   
                                                   上。   
            
    -->


    4、然后修改Domain對象,對于要使用緩存的的Entity,在類聲明前加上如下的標簽:<BR>@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE),此處usage的值還需要根據應用情況進行必要的調整。<BR> </P><P>5、暫時使用ehcache作為Spring modules的cache。在ehcache.xml文件中繼續配置用于為spring提供方法調用結果的緩存。大致如下:

    <!--以下是為Spring提供的方法調用結果緩存-->  
          
     
    <CACHE name="CMSCache" maxelementsinmemory="5000" eternal="false" overflowtodisk="true" memorystoreevictionpolicy="LFU"></CACHE>  
     
    <CACHE name="ECCache" maxelementsinmemory="5000" eternal="false" overflowtodisk="true" memorystoreevictionpolicy="LFU"></CACHE>


    6、然后在具體的Service類中配置緩存。使用了AOP,需要修改spring的配置文件,比如cms-core.xml中為了給ICmsManageService的get*方法添加結果緩存,調整如下:

    <EHCACHE:PROXY id=cmsManageService>     
     
    <BEAN class=com.easyjf.cms.service.impl.CmsManageServiceImpl></BEAN>     
      
    <property name="newsAuthorDao" ref="newsAuthorDao"></property>  
      
    <property name="newsDocDao" ref="newsDocDao"></property>  
      
    <property name="newsDirDao" ref="newsDirDao"></property>  
      
    <property name="newsSourceDao" ref="newsSourceDao"></property>  
      
    <property name="reviewDao" ref="newsRivewDao"></property>  
        
     
    <EHCACHE:CACHING cachename="CMSCache" methodname="get*"></EHCACHE:CACHING>  
     
    <EHCACHE:FLUSHING methodname="update*" cachenames="CMSCache" when="before"></EHCACHE:FLUSHING>  
     
    </EHCACHE:PROXY>


    調整前對照: 

    <BEAN class=com.easyjf.cms.service.impl.CmsManageServiceImpl id=cmsManageService></BEAN>     
      
    <property name="newsAuthorDao" ref="newsAuthorDao"></property>  
      
    <property name="newsDocDao" ref="newsDocDao"></property>  
      
    <property name="newsDirDao" ref="newsDirDao"></property>  
      
    <property name="newsSourceDao" ref="newsSourceDao"></property>  
      
    <property name="reviewDao" ref="newsRivewDao"></property> 


    為了讓Spring配置文件能識別并處理<EHCACHE:XXX>這個標簽,需要在beans中進行schem聲明,如下所示:<BR>另外在spring配置文件中再增加<EHCACHE:CONFIG configlocation="classpath:ehcache.xml"></EHCACHE:CONFIG>,以便Spring能找到Cache配置文件。</EHCACHE:XXX>

    <BEANS xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:ehcache="http://www.springmodules.org/schema/ehcache" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd        http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd"></BEANS>  
       


    7、以上只是基本的配置,cache運行的具體性能,還需要根據實際的數據量及并發量等進行更加細致的調整。

    8、另外EasyJWeb還將會提供一個頁面結果緩存,直接緩存Action的執行結果,這樣就可以解決訪問得最多,屬于嚴重性能瓶頸的問題。比如ec-brand.ejf、index.ejf等。這一功能將在9月15號前推出。

    9、一些必要的頁面,需要增加靜態文件生成功能。(逐漸調整)

    注釋:

     由于發現Spring2.06版本與當前我們使用的版本存在一些沖突。而且跟EasyJWeb中的maven混合編譯的時候存在一些問題,因此暫時取消使用Spring的方法Cache,而只使用Hibernate的Cache及EasyJWeb的緩存配合。EasyJWeb的緩存簡單機制已經實現,直接在基于AbstractCmdAction的Action中,在要緩存的Command中使用緩存標簽@WebCache即可。

    posted on 2007-11-28 16:53 簡易java框架 閱讀(1292) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 国产免费变态视频网址网站| 亚洲黄色三级网站| 亚洲丁香婷婷综合久久| 免费在线看v网址| 亚洲熟妇无码爱v在线观看| 在线成人精品国产区免费| 亚洲日韩欧洲乱码AV夜夜摸| 中文日本免费高清| 久久精品视频亚洲| 59pao成国产成视频永久免费| 亚洲国产婷婷六月丁香| 免费A级毛片无码视频| 亚洲欧洲校园自拍都市| 国产精品视频永久免费播放| 亚洲人成人伊人成综合网无码| 日韩高清免费观看| 一级毛片免费不卡| 亚洲韩国—中文字幕| 无码免费午夜福利片在线| 国产精品亚洲а∨无码播放麻豆 | 国产∨亚洲V天堂无码久久久| 免费一级毛片无毒不卡| 亚洲性色高清完整版在线观看| 在线观看www日本免费网站| 亚洲中文字幕久久无码| 一区国严二区亚洲三区| 免费毛片a线观看| 久久精品亚洲AV久久久无码 | 女bbbbxxxx另类亚洲| 亚洲中文字幕在线第六区| 96免费精品视频在线观看| 亚洲熟妇无码一区二区三区导航| 免费少妇a级毛片| 99热精品在线免费观看| 亚洲6080yy久久无码产自国产 | 亚洲国产激情一区二区三区| 亚洲精品免费观看| 日韩色日韩视频亚洲网站| 久久精品国产精品亚洲艾草网| 成人性生交视频免费观看| 两个人看的www免费高清|