閑人野居
          好好學(xué)習(xí),天天向上
          posts - 57,  comments - 137,  trackbacks - 0

          ??? 一直以來懶得配置緩存,基本的緩存也就是orm層,基本上都交給hibernate去配置了。這段時(shí)間,感覺頁面速度太慢了,還是需要使用緩存?,F(xiàn)在的緩存工具也挺多的,較不錯(cuò)的屬ehcache和oscache了。決定分別研究一下。
          ??? 先來說說ehcache,目前的版本為1.2,已經(jīng)支持集群了。對于ehcache的使用,感覺很容易上手,基本上都是配置。以前在hibernate的時(shí)候配置過,所以也不是很陌生。API也挺簡單,如下的api:
          ??? CacheManager主要的緩存管理類,一般一個(gè)應(yīng)用為一個(gè)實(shí)例,如下
          ??? CacheManager.create();也可以使用new CacheManager的方式創(chuàng)建
          ???? 默認(rèn)的配置文件為ehcache.xml文件,也可以使用不同的配置:
          ??? ?
          ?
          CacheManager manager = new CacheManager("src/config/other.xml");?? ?

          緩存的創(chuàng)建,采用自動的方式
          ?
          CacheManager singletonManager = CacheManager.create();
          singletonManager.addCache("testCache");
          Cache test = singletonManager.getCache("testCache");?? ?

          或者直接創(chuàng)建Cache

          ?
          CacheManager singletonManager = CacheManager.create();
          Cache memoryOnlyCache = new Cache("testCache", 5000, false, false, 5, 2);
          manager.addCache(memoryOnlyCache);
          Cache test = singletonManager.getCache("testCache");?? ?

          刪除cache
          ?
          CacheManager singletonManager = CacheManager.create();
          singletonManager.removeCache("sampleCache1");?? ?

          在使用ehcache后,需要關(guān)閉
          ?
          CacheManager.getInstance().shutdown()?? ?

          caches 的使用

          ?
          Cache cache = manager.getCache("sampleCache1");?? ?

          執(zhí)行crud操作

          ?
          Cache cache = manager.getCache("sampleCache1");
          Element element = new Element("key1", "value1");
          cache.put(element);?? ?

          update
          ?
          Cache cache = manager.getCache("sampleCache1");
          cache.put(new Element("key1", "value1");
          //This updates the entry for "key1"
          cache.put(new Element("key1", "value2");?? ?

          get Serializable

          ?
          Cache cache = manager.getCache("sampleCache1");
          Element element = cache.get("key1");
          Serializable value = element.getValue();?? ?

          get non serializable
          ?
          Cache cache = manager.getCache("sampleCache1");
          Element element = cache.get("key1");
          Object value = element.getObjectValue();?? ?

          remove
          ?
          Cache cache = manager.getCache("sampleCache1");
          Element element = new Element("key1", "value1"
          cache.remove("key1");?? ?

          不過緩存還是基本上以配置方式為主,下一篇文章將會說明ehcache如何配置
          ?? ?

          ?? ?
          ?? ?

          posted on 2007-02-28 20:14 布衣郎 閱讀(24229) 評論(15)  編輯  收藏 所屬分類: jdk相關(guān)

          FeedBack:
          # re: 使用ehcache
          2007-03-01 20:58 | 山風(fēng)小子
          如果有個(gè)完整的小例子就更好了:)  回復(fù)  更多評論
            
          # re: 使用ehcache
          2007-03-02 17:34 | itVincent
          同意樓上,有個(gè)例子更好  回復(fù)  更多評論
            
          # re: 使用ehcache
          2008-01-01 17:42 | bizairshop
          跟hibernate結(jié)合在一起的時(shí)候不需要寫這些代碼,只要配置一下即可。
          航服機(jī)票推薦 http://www.bizairshop.com   回復(fù)  更多評論
            
          # re: 使用ehcache
          2008-01-19 08:52 | tt168
          要是沒用hibernate呢
          我用的jsp+javabeans,請問怎么用ehcache

          我的MSN:mugesoft@hotmail.com,歡迎指教  回復(fù)  更多評論
            
          # re: 使用ehcache[未登錄]
          2008-05-12 09:38 | jacky
          要是沒用hibernate呢
          我用的jsp+javabeans,請問怎么用ehcache

          我的MSN:jackyxiao@live.cn,歡迎指教  回復(fù)  更多評論
            
          # 我很愛錢
          2008-05-20 21:22 | 愛看書
          北京到卡諾機(jī)票|北京到卡諾飛機(jī)票價(jià)格查詢|預(yù)定北京到卡諾機(jī)票

          航程: 卡諾機(jī)票,北京到卡諾機(jī)票
          機(jī)票價(jià)格: 單程:4500元 往返:6200元
          航空公司: 中國國際航空公司
          稅費(fèi)規(guī)定: 國際機(jī)票的價(jià)格由票價(jià)、稅金、燃油費(fèi)組成。航空公司、艙位、有效期、退改簽和機(jī)票限制等規(guī)定決定了票價(jià)的高低;稅金因?yàn)楦鶕?jù)每天的匯率會不同,所以具體金額會以您出票當(dāng)天為準(zhǔn).機(jī)場建設(shè)費(fèi)則是由民航總局規(guī)定乘坐國際航班,每人90元,嬰兒、兒童免收機(jī)場建設(shè)費(fèi).此價(jià)格在有效期內(nèi)針對中國國內(nèi)乘客有效,
          說明: 1.兒童票價(jià)為成人票價(jià)的75%。嬰兒票價(jià)為公布運(yùn)價(jià)的10%。
          2.可在機(jī)票有效期內(nèi)免費(fèi)修改預(yù)訂.
          4.以上票價(jià)以人民幣結(jié)算,不含稅,稅后價(jià)格以電話查詢?yōu)闇?zhǔn).
          退票條件:以承運(yùn)航空公司退票規(guī)定退票
          <a href="http://2008sjjp.com/jipiao/115617681.html">北京到卡諾機(jī)票.北京到卡諾機(jī)票價(jià)格.北京-卡諾航班諾</a>
          <a href="http://2008sjjp.com/jipiao/115546152.html">北京到拉各斯機(jī)票.北京到拉各斯機(jī)票價(jià)格.北京-拉各斯航班</a>
            回復(fù)  更多評論
            
          # re: 使用ehcache
          2008-05-29 21:19 | BT下載
          http://www.5a520.cn 小說520網(wǎng)  回復(fù)  更多評論
            
          # re: 使用ehcache
          2008-12-16 15:49 | 養(yǎng)藏獒
          如果詳細(xì)點(diǎn)就好了
          有點(diǎn)不明白  回復(fù)  更多評論
            
          # re: 使用ehcache
          2009-03-17 16:28 | 12312
          # re: 使用ehcache
          2012-07-02 09:44 | 馬云
          # re: 使用ehcache
          2012-07-02 09:45 | 馬云

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


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

          <2007年2月>
          28293031123
          45678910
          11121314151617
          18192021222324
          25262728123
          45678910

          常用鏈接

          留言簿(12)

          隨筆分類(59)

          隨筆檔案(57)

          blog

          java

          uml

          搜索

          •  

          積分與排名

          • 積分 - 358221
          • 排名 - 156

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 哈尔滨市| 彭阳县| 七台河市| 垦利县| 缙云县| 江达县| 南乐县| 梓潼县| 宿松县| 邓州市| 丹巴县| 江达县| 积石山| 裕民县| 和田市| 堆龙德庆县| 兰坪| 商洛市| 平昌县| 莒南县| 凤城市| 泗阳县| 土默特右旗| 屏山县| 金溪县| 永和县| 松滋市| 大宁县| 沂南县| 紫云| 大石桥市| 大化| 临江市| 石首市| 盐边县| 手游| 鸡西市| 开江县| 景谷| 青海省| 文安县|