理解hibernate高速二级缓存区域
<p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">Hibernate</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Couriernew';">在不同的高速缓存区域(</span><span style="font-family:'Courier New';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">cache region</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Courier New';mso-bidi-font-family:'Couriernew';">)保存不同的类</span><span style="font-family:'Courier New';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">/</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">集合。</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <!--?xml:namespace prefix = o /--> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">区域即是一个具有名称的高速缓存块,你可以给每一个高速缓存块设置不同的缓存策略。如果没有设置任何的缓存区域,</span><span style="font-family:'Courier New';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Courier New';mso-bidi-font-family:'Couriernew';">则所有被缓存的对象,都将使用默认的缓存策略。即:</span><span style="font-family:'Courier New';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"><defaultCache.../> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">对于类而言,区域的名称是类名。如</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">:cn.itcast.domain.Person(</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">一般情况后面会跟一个</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">.data) <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">对于集合而言,区域的名称是类名加属性名。如</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">cn.itcast.domain.Person.cars(</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">一般情况,后面会跟一个</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">.data) <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> hibernate</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">的配置属性:</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">hibernate.cache.region_prefix</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">可以给每一个区域配置一个前缀的名称。但这种情况一般发生在一个项目中</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">有多个</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">SessionFactory</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">的情况。如果一个项目有多个</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">SessionFactory</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">则此配置也是必须的。</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">以下是示例:</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">ehcache</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">的具名缓存区域配置示例:</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> </span><span style="font-family:'Courier New';font-size:10pt;mso-font-kerning:0pt;mso-ansi-language:FR;" lang="FR"><ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;mso-ansi-language:FR;" lang="FR"> </span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">xsi:noNamespaceSchemaLocation="ehcache.xsd" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> updateCheck="true" monitoring="autodetect" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> dynamicConfig="true"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <diskStore path="d:/a"/> //</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Courier New';mso-bidi-font-family:'Couriernew';">指定文件保存路径</span><span style="font-family:'Courier New';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <defaultCache //</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">配置默认缓存区域,这是必须配置项。如果没有给某个类设置缓存区域,它将使用默认缓存区域</span><span style="font-family:'Courier New';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> maxElementsInMemory="100" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> eternal="false" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> timeToIdleSeconds="120" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> timeToLiveSeconds="300" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> overflowToDisk="true" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> /> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <cache name="<b><span style="color:red;">cn.itcast.domain.Person</span></b>" //</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Courier New';mso-bidi-font-family:'Couriernew';">指定</span><span style="font-family:'Courier New';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">Person</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">类的缓存区域,所有</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">Person</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">类,都会保存在此区域</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> maxElementsInMemory="2" //</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">故意指定内存中放很少的数据,以观察生成的文件大小</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> eternal="false" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> timeToIdleSeconds="120" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> timeToLiveSeconds="300" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> overflowToDisk="true" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> diskPersistent="true" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> diskExpiryThreadIntervalSeconds="120" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> maxElementsOnDisk="100" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> > <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> </cache> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"></ehcache> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">测试代码:一次生成多个</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US">Person</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">实例,看看生成的文件大小:</span><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> Session s1 = HibernateUtils.openSession(); <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> Person p1 = (Person) s1.get(Person.class,"11"); <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> Person p2 = (Person) s1.get(Person.class,"402880e <!--?xml:namespace prefix = st1 /--> <st1:chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="6346" unitname="F"> 6346f </st1:chmetcnv>5ffe <st1:chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1346" unitname="F"> 01346f </st1:chmetcnv>6000b50000"); <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-family:'Couriernew';font-size:10pt;mso-font-kerning:0pt;" lang="EN-US"> Person p3 = (Person) s1.get(Person.class,"402880e6347311fa01347311fb <st1:chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="7" unitname="C"> 7c </st1:chmetcnv>0000"); <o:p></o:p></span></p> <span style="font-family:'Courier New';font-size:10pt;mso-ansi-language:EN-US;mso-fareast-font-family:宋体;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA;" lang="EN-US"> s1.close();<br /> <!--[if !supportLineBreakNewLine]--><h4><span lang="EN-US">1</span><span style="font-family:黑体;mso-font-kerning:0pt;mso-ascii-font-family:Arial;">、理解高速<span style="color:red;">查询</span>缓存区域</span><span lang="EN-US"> <o:p></o:p></span></h4> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">当某个查询第一次执行时,它的结果被高速缓存在高速缓存区域--注意,这个区域不同于你可能已经配置的任何其他实例或</span><span style="font-size:10pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">集合高速缓存区域。这个区域的名称默认为</span><span style="font-size:10pt;" lang="EN-US">:org.hibernate.cache.StandardQueryCache</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">。</span><span style="font-size:10pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">可以通过</span><span style="font-size:10pt;" lang="EN-US">setCacheRegion(...)</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">方法,给一个特定的查询改变高速缓存区域。</span><span style="font-size:10pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> hql = "from Person where name='JackB'"; <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> list = s.createQuery(hql) <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> .setCacheable(true) <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> .setCacheRegion("itcast") //</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Courier New';mso-bidi-font-family:'Couriernew';">改变默认缓存查询区域</span><span style="font-size:10pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> .list(); <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">或是显示的设置一个查询缓存区域,以观察它的保存情况:</span><span style="font-size:10pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> <cache name="org.hibernate.cache.StandardQueryCache" //</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Courier New';mso-bidi-font-family:'Couriernew';">必须叫这个名称</span><span style="font-size:10pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> maxElementsInMemory="2" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> eternal="false" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> timeToIdleSeconds="120" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> timeToLiveSeconds="300" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> overflowToDisk="true" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> diskPersistent="true" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> diskExpiryThreadIntervalSeconds="120" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> maxElementsOnDisk="100" <o:p></o:p></span></p> <p style="text-align:left;mso-layout-grid-align:none;" class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> /><br /> <br /> </span></p><h4><span lang="EN-US">2</span><span style="font-family:黑体;mso-font-kerning:0pt;mso-ascii-font-family:Arial;">、时间戳高速缓存区域</span><span lang="EN-US"> <o:p></o:p></span></h4> <p class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">如果查询结果高速缓存被启用,另一个始终需要的高速缓存区域也出现了:</span><span style="font-size:10pt;" lang="EN-US">org.hibernate.cache.UpdateTimestampsCache</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">。</span><span style="font-size:10pt;" lang="EN-US"> <o:p></o:p></span></p> <p class="MsoNormal"><span style="font-size:10pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">这是</span><span style="font-size:10pt;" lang="EN-US">Hibernate</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">内部使用的一个高速缓存区域。</span><span style="font-size:10pt;" lang="EN-US">Hibernate</span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">用时间戳来决定被高速缓存的结果集是否已经失效。<br /> </span><span style="font-size:10pt;" lang="EN-US"> <o:p></o:p></span></p> <br /> <h3><span style="font-family:宋体;mso-font-kerning:0pt;mso-ascii-font-family:'Times New Roman';mso-hansi-font-family:'Times Newroman';">使用二级缓存的项目建议</span><span lang="EN-US"> <o:p></o:p></span></h3> <p class="MsoNormal" align="left"><span style="font-size:10pt;" lang="EN-US"> </span><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Courier New';mso-hansi-font-family:'Couriernew';mso-bidi-font-family:'Courier New';">并非所有的类都可以受益于高速二级缓存,因为,能够禁用高速二级缓存也很重要。重申一下,高速缓存通常只对于主要用来读取的</span><span style="font-size:10pt;" lang="EN-US"> <o:p></o:p></span></p> <p class="MsoNormal" align="left"><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Courier New';mso-bidi-font-family:'Couriernew';">类有用。如果你有更新比读取更经常的数据,就不要启用二级高速缓存,即使所有其他的高速缓存条件都符合!</span><span style="font-size:10pt;" lang="EN-US"> <o:p></o:p></span></p> <p style="text-indent:21pt;" class="MsoNormal"><span style="font-family:宋体;font-size:10pt;mso-font-kerning:0pt;mso-ascii-font-family:'Couriernew';mso-hansi-font-family:'Courier New';mso-bidi-font-family:'Couriernew';">更新期间,维护高速缓存的代价可能远远超出更快读取的性能受益。</span><span style="font-size:10pt;" lang="EN-US"> <o:p></o:p></span></p> <br /> <br /> <br /> <o:p></o:p></span> <p></p> <!--[endif]-->
本文由用户 wangjianme 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!