blog.Toby

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            130 隨筆 :: 2 文章 :: 150 評(píng)論 :: 0 Trackbacks

          1 環(huán)境要求
                  OSCache2.2要求JDK1.4和 Servlet 2.3。
          2 安裝
                  (1)http://www.opensymphony.com/oscache/下載合適的OSCache版本,當(dāng)前是oscache-2.0.2-full版本。
                  (2)Zip文件解壓縮到c:\oscache(后面的章節(jié)中將使用%OSCache_Home%來表示這個(gè)目錄)目錄下。
                  (3)將主要組件%OSCache_Home%\oscache.jar文件放到  /WEB-INF/lib或相應(yīng)類庫目錄中。jar文件名可能含有版本號(hào)和該版本的發(fā)布日期信息等,如oscache-2.2.jar。
                  (4)引用包的處理:
                      ①OSCache組件用Jakarta Commons Logging來處理日志信息,所以需要commons-logging.jar的支持,將commons-logging.jar放入classpath。
                      ②如果使用JDK1.3,將commons-collections.jar放入classpath,如果使用JDK1.4或者以上版本則不必。
                      ③如果需要集群緩存,把jgroups.jar放入classpath。


          3 配置

          3.1 緩存配置 
                  src\webapp\WEB-INF\classes或etc目錄取得oscache.properties文件,放在CLASSPATH下(src根目錄或發(fā)布環(huán)境的/WEB-INF/classes  目錄)。
                  oscache.properties包含了對(duì)OSCache運(yùn)行特征值的設(shè)置信息 ,其配置項(xiàng)如下:
           

          配置項(xiàng)

          含義

          可選值

          缺省值

          cache.memory

          是否進(jìn)行內(nèi)存緩存

          truefalse

          true

          cache.capacity

          內(nèi)存緩存容納的最大對(duì)象數(shù)

          整數(shù)

          不限制(指定負(fù)數(shù)也相當(dāng)于不限制),也就是緩存的對(duì)象從不被清除

          cache.algorithm

          缺省的運(yùn)算規(guī)則。要指定運(yùn)算規(guī)則,就必須指定有效的cache.capacity值(正整數(shù))。規(guī)則是一些類,在包com.opensymphony.oscache.base.algorithm

          LRUCache(最近使用)、

          FIFOCache(先進(jìn)先出)、

          UnlimitedCache(不限制)

          不限制cache.capacity時(shí)為UnlimitedCache

          If you specify a size but not an algorithm, the cache algorithm used will be LRUCache

          cache.blocking

          當(dāng)緩存中的某條數(shù)據(jù)更新時(shí)(比如與數(shù)據(jù)庫不同步,存在不新鮮的數(shù)據(jù)),對(duì)客戶請(qǐng)求返回更新前的數(shù)據(jù)。這樣就提供了更好的性能。

          truefalse

          false

          cache.unlimited.disk

          硬盤緩存是否有限制。缺省為cache.capacity指定的值

          truefalse

          false

          cache.persistence.class

          做持久化操作的類名。這個(gè)類必須實(shí)現(xiàn)PersistenceListener接口,從而將緩存數(shù)據(jù)持久化到文件、數(shù)據(jù)庫、LDAPOSCache給出一個(gè)基于文件系統(tǒng)的實(shí)現(xiàn),并且使用對(duì)象的toString()方法生成要持久化數(shù)據(jù)的文件名。HashDiskPersistenceListener DiskPersistenceListener要求必須同時(shí)設(shè)置cache.path屬性。

          com.opensymphony

          .oscache.plugins

          .diskpersistence

          .DiskPersistenceListener 

           

          cache.path

          硬盤持久化時(shí)存放文件的目錄。如果目錄不存在OSCache會(huì)自動(dòng)創(chuàng)建。

          Windows系統(tǒng):

          c:\\myapp\\cache

          其它:

          /opt/myapp/cache

           

          cache.persistence.overflow.only*

          是否只有當(dāng)指定的內(nèi)存緩存已經(jīng)滿時(shí)才進(jìn)行持久化。推薦使用trueflase是為向后兼容。

          truefalse

          false

          cache.event.listeners

          一系列用逗號(hào)分割的類,這些類必須實(shí)現(xiàn)CacheEntryEventListener或(和)CacheMapAccessEventListener接口,CacheEntryEventListener監(jiān)聽緩存的add/update/flush/remove事件,CacheMapAccessEventListener監(jiān)聽緩存的access事件,從而可以跟蹤并統(tǒng)計(jì)緩存的執(zhí)行效率。

          JavaDoc API for further details.

           

           

          cache.key

          指定在applicationsession范圍里緩存的對(duì)象的key,這個(gè)keyServletCacheAdministrator(由此自定義的tags)使用。

           

          __oscache_cache

          cache.use.host.domain.in.key

          If your server is configured with multiple hosts, you may wish to add host name information to automatically generated cache keys. If so, set this property to true

          truefalse

          false

          cache.cluster.multicast.ip

          見集群的相關(guān)說明

           

           

          cache.cluster.properties

          見集群的相關(guān)說明

           

           


                  注:*從2.1版本開始出現(xiàn)的屬性

          3.2 日志配置

                  log4j.properties文件內(nèi)容為:

          log4j.rootLogger=DEBUG,stdout,file

          log4j.appender.stdout=org.apache.log4j.ConsoleAppender
          log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
          log4j.appender.stdout.layout.ConversionPattern=[start]%d{yyyy/MM/dd/ HH:mm:ss}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD]%n%c[CATEGORY]%n%m[MESSAGE]%n%n

          log4j.appender.file=org.apache.log4j.RollingFileAppender
          log4j.appender.file.File=oscache.log
          log4j.appender.file.MaxFileSize=100KB
          log4j.appender.file.MaxBackupIndex=5
          log4j.appender.file.layout=org.apache.log4j.PatternLayout
          log4j.appender.file.layout.ConversionPattern=[start]%d{yyyy/MM/dd/ HH:mm:ss}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD] n%c[CATEGORY]%n%m[MESSAGE]%n%n

          log4j.logger.org.apache.commons=ERROR
          log4j.logger.com.opensymphony.oscache.base=INFO

          commons-logging.properties 文件內(nèi)容為
          org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JCategoryLog

           

          posted on 2006-01-12 16:52 渠上月 閱讀(2380) 評(píng)論(1)  編輯  收藏 所屬分類: java tips

          評(píng)論

          # re: OScache的安裝與配置 2007-04-29 13:30 piper
          博主,
          你好,你的文章寫的不錯(cuò),最近我也在使用oscache,能不能再進(jìn)一步寫一些有關(guān)的文章,關(guān)于新版本2.3.1的新功能之類的,或者高級(jí)應(yīng)用比如集群中,或者oacache的原理和剖析之類的,呵呵,主要是看博主的時(shí)間了。
          我的msn
          sardingking@hotmail.com  回復(fù)  更多評(píng)論
            

          主站蜘蛛池模板: 丽江市| 花莲县| 通渭县| 柳河县| 麻城市| 应用必备| 奉贤区| 吉隆县| 三亚市| 安溪县| 闽侯县| 三明市| 阿拉善左旗| 革吉县| 阿坝县| 卫辉市| 政和县| 阳谷县| 什邡市| 宜春市| 乌拉特中旗| 苏尼特右旗| 苏尼特左旗| 密山市| 大邑县| 芦溪县| 康马县| 康平县| 永兴县| 肥乡县| 诏安县| 炎陵县| 子洲县| 沧源| 修武县| 新丰县| 罗定市| 日照市| 阳信县| 徐汇区| 新巴尔虎右旗|