西瓜地兒
沈陽(yáng)求職(java3年以上經(jīng)驗(yàn))!ashutc@126.com
BlogJava
|
首頁(yè)
|
發(fā)新隨筆
|
發(fā)新文章
|
聯(lián)系
|
聚合
|
管理
隨筆:114 文章:1 評(píng)論:45 引用:0
Hibernate二級(jí)緩存ehcache配置
需要兩個(gè)包:
commons-logging-1.0.4.jar
ehcache-1.2.3.jar
在src根目錄下新建 ehcache.xml
<?
xml version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
<
ehcache
>
<
diskStore path
=
"
java.io.tmpdir
"
/>
<
defaultCache maxElementsInMemory
=
"
10000
"
eternal
=
"
false
"
timeToIdleSeconds
=
"
120
"
timeToLiveSeconds
=
"
120
"
overflowToDisk
=
"
true
"
diskExpiryThreadIntervalSeconds
=
"
120
"
memoryStoreEvictionPolicy
=
"
LRU
"
/>
<
cache name
=
"
cn.yu.vo.Guestbook
"
maxElementsInMemory
=
"
1000
"
eternal
=
"
false
"
timeToIdleSeconds
=
"
3000
"
timeToLiveSeconds
=
"
600
"
overflowToDisk
=
"
true
"
/>
</
ehcache
>
<!--
diskStore:保存在硬盤(pán)上的臨時(shí)目錄
name:Cache的唯一標(biāo)識(shí)
maxElementsInMemory:內(nèi)存中最大緩存對(duì)象數(shù)。
maxElementsOnDisk:磁盤(pán)中最大緩存對(duì)象數(shù),若是0表示無(wú)窮大。
eternal:Element是否永久有效,一但設(shè)置了,timeout將不起作用。
overflowToDisk:配置此屬性,當(dāng)內(nèi)存中Element數(shù)量達(dá)到maxElementsInMemory時(shí),Ehcache將會(huì)Element寫(xiě)到磁盤(pán)中。
timeToIdleSeconds:設(shè)置Element在失效前的允許閑置時(shí)間。僅當(dāng)element不是永久有效時(shí)使用,可選屬性,默認(rèn)值是0,
也就是可閑置時(shí)間無(wú)窮大。
timeToLiveSeconds:設(shè)置Element在失效前允許存活時(shí)間。最大時(shí)間介于創(chuàng)建時(shí)間和失效時(shí)間之間。僅當(dāng)element不是永久
有效時(shí)使用,默認(rèn)是0., 也就是element存活時(shí)間無(wú)窮大。
diskPersistent:是否緩存虛擬機(jī)重啟期數(shù)據(jù)。(這個(gè)虛擬機(jī)是指什么虛擬機(jī)一直沒(méi)看明白是什么,有高人還希望能指點(diǎn)
一二)。
diskExpiryThreadIntervalSeconds:磁盤(pán)失效線程運(yùn)行時(shí)間間隔,默認(rèn)是120秒。
diskSpoolBufferSizeMB:這個(gè)參數(shù)設(shè)置DiskStore(磁盤(pán)緩存)的緩存區(qū)大小。默認(rèn)是30MB。每個(gè)Cache都應(yīng)該有自己的一
個(gè)緩沖區(qū)。
memoryStoreEvictionPolicy:當(dāng)達(dá)到maxElementsInMemory限制時(shí),Ehcache將會(huì)根據(jù)指定的策略去清理內(nèi)存。默認(rèn)策略是
LRU(最近最少使用)。你可以設(shè)置為FIFO(先進(jìn)先出)或是LFU(較少使用)。這里比較
遺憾,Ehcache并沒(méi)有提供一個(gè)用戶定制策略的接口,僅僅支持三種指定策略,感覺(jué)做的不夠
理想。
-->
在hibernate.cfg.xml里面新增屬性
<
property name
=
"
cache.provider_class
"
>
org.hibernate.cache.EhCacheProvider
</
property
>
在guestbook.hbm.xml里面新增屬性
<
class
name
=
"
cn.yu.vo.Guestbook
"
table
=
"
GUESTBOOK
"
schema
=
"
OLIVER
"
>
<
cache usage="read-write"
/>
<
id name
=
"
id
"
type
=
"
java.lang.Long
"
>
<
column name
=
"
ID
"
precision
=
"
22
"
scale
=
"
0
"
/>
<
generator
class
=
"
sequence
"
>
<
param name
=
"
sequence
"
>
gb_seq
</
param
>
</
generator
>
</
id
>
發(fā)表于 2009-10-31 15:45
西瓜
閱讀(946)
評(píng)論(2)
編輯
收藏
所屬分類(lèi):
java框架
評(píng)論
#
re: Hibernate二級(jí)緩存ehcache配置
為什么我不配置這個(gè)文件,也可以使用緩存。
游客
評(píng)論于 2011-01-05 18:38
回復(fù)
更多評(píng)論
#
re: Hibernate二級(jí)緩存ehcache配置
@游客
hibernate 本身有自己的緩存機(jī)制。使用第三方的二級(jí)緩存只是因?yàn)榉奖愫托阅苌系膬?yōu)點(diǎn)
西瓜
評(píng)論于 2011-01-19 09:12
回復(fù)
更多評(píng)論
新用戶注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
相關(guān)文章:
spring3.0注解
3:aop實(shí)現(xiàn),2.0中pointcut的定義
2:aop實(shí)現(xiàn)-spring2.0中的aop實(shí)現(xiàn)
1:aop實(shí)現(xiàn)-advice
spring 3.0 mvc
no matching editors or conversion strategy(配置事物時(shí)出現(xiàn)的錯(cuò)誤)
用Spring提供的JUnit框架擴(kuò)展對(duì)DAO或Service層進(jìn)行單元測(cè)試
Unable to load configuration. - bean - jar:file:/D:/Tomcat-6.0.18/webapps/teabank/WEB-INF/lib/struts2-core-2.1.6.jar!/struts-default.xml
struts2 文件上傳及縮放
userlogin
<
2011年1月
>
日
一
二
三
四
五
六
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
常用鏈接
我的隨筆
我的評(píng)論
我的參與
最新評(píng)論
留言簿
(2)
給我留言
查看公開(kāi)留言
查看私人留言
隨筆分類(lèi)
(116)
ajax(1)
(rss)
c3p0(2)
(rss)
fedora(1)
(rss)
Hadoop(2)
(rss)
IBATIS(2)
(rss)
ICE(1)
(rss)
ICE中間件
(rss)
java(10)
(rss)
javaMail(1)
(rss)
javaScript(2)
(rss)
java框架(22)
(rss)
jbpm(4)
(rss)
JDBC(3)
(rss)
JSTL(1)
(rss)
Junit(3)
(rss)
Linux(5)
(rss)
Log4j(2)
(rss)
Lucene(7)
(rss)
maven(1)
(rss)
MongoDb(8)
(rss)
oracle(2)
(rss)
Quartz調(diào)度(1)
(rss)
SQL(4)
(rss)
TEMP(17)
(rss)
WEBSERVICES(2)
(rss)
內(nèi)存(2)
(rss)
存儲(chǔ)過(guò)程(1)
(rss)
數(shù)據(jù)庫(kù)設(shè)計(jì)(4)
(rss)
正則表達(dá)式(5)
(rss)
隨筆檔案
(114)
2011年6月 (3)
2011年5月 (5)
2011年4月 (6)
2011年3月 (4)
2011年2月 (2)
2011年1月 (3)
2010年12月 (8)
2010年11月 (9)
2010年10月 (6)
2010年9月 (7)
2010年8月 (4)
2010年7月 (8)
2010年6月 (5)
2010年5月 (2)
2010年4月 (1)
2010年3月 (1)
2010年1月 (10)
2009年12月 (4)
2009年11月 (6)
2009年10月 (4)
2009年9月 (2)
2009年7月 (2)
2009年6月 (3)
2009年5月 (6)
2009年3月 (3)
文章分類(lèi)
(1)
觀風(fēng)(1)
(rss)
文章檔案
(1)
2009年8月 (1)
搜索
最新評(píng)論
1.?re: Lucene的檢索優(yōu)化(轉(zhuǎn))[未登錄](méi)
好,64個(gè)贊
--liang
2.?re: jbpm4.3流程圖插件亂碼問(wèn)題和name輸入刷新問(wèn)題
評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
--朗天
3.?re: c3p0詳細(xì)配置
評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
--Darren
4.?re: spring3.0注解
不錯(cuò)
--煩煩煩
5.?re: 如何寫(xiě)出高效率的sql語(yǔ)句
不錯(cuò)很有參考價(jià)值。
--隱身
閱讀排行榜
1.?Python模塊學(xué)習(xí) --- urllib(50378)
2.?利用 org.apache.commons.io.FileUtils快速讀寫(xiě)文件(30121)
3.?spring3.0注解(21108)
4.?maven的pom.xml(20549)
5.?利用CXF框架開(kāi)發(fā)WebService(轉(zhuǎn))(17957)
評(píng)論排行榜
1.?Python模塊學(xué)習(xí) --- urllib(12)
2.?spring3.0注解(7)
3.?jquery實(shí)現(xiàn)無(wú)刷新圖片驗(yàn)證(4)
4.?如何寫(xiě)出高效率的sql語(yǔ)句(4)
5.?jbpm4.3流程圖插件亂碼問(wèn)題和name輸入刷新問(wèn)題(3)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 西瓜
主站蜘蛛池模板:
册亨县
|
哈巴河县
|
吉木萨尔县
|
绍兴县
|
乌什县
|
双桥区
|
林西县
|
南丹县
|
闻喜县
|
榆中县
|
上虞市
|
抚州市
|
浮梁县
|
邵东县
|
手游
|
分宜县
|
蒙阴县
|
灌云县
|
耒阳市
|
巨野县
|
平定县
|
神池县
|
滦平县
|
云龙县
|
淳化县
|
怀集县
|
土默特左旗
|
峨山
|
荔浦县
|
静海县
|
化州市
|
彰化县
|
通化县
|
梧州市
|
曲沃县
|
宁都县
|
抚州市
|
安福县
|
青岛市
|
广州市
|
平罗县
|