閑人野居
          好好學習,天天向上
          posts - 57,  comments - 137,  trackbacks - 0

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

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

          或者直接創建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后,需要關閉
          ?
          CacheManager.getInstance().shutdown()?? ?

          caches 的使用

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

          執行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 布衣郎 閱讀(24212) 評論(15)  編輯  收藏 所屬分類: jdk相關

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

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

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

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

          <2008年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(12)

          隨筆分類(59)

          隨筆檔案(57)

          blog

          java

          uml

          搜索

          •  

          積分與排名

          • 積分 - 357332
          • 排名 - 155

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 乌拉特前旗| 平山县| 集安市| 福建省| 额济纳旗| 平原县| 丘北县| 成都市| 江达县| 博客| 革吉县| 个旧市| 遵义市| 杨浦区| 晋中市| 高密市| 城固县| 沾化县| 平山县| 岑溪市| 河津市| 铁岭市| 江川县| 宜兰县| 平顶山市| 金沙县| 镇宁| 平和县| 普宁市| 仁怀市| 田阳县| 新竹市| 鸡泽县| 石楼县| 平遥县| 白沙| 色达县| 中牟县| 阿拉善右旗| 门源| 会理县|