Oracle神諭

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            284 隨筆 :: 9 文章 :: 106 評論 :: 0 Trackbacks

          20.2.1. 緩存映射(Cache mappings)

          類或者集合映射的“<cache>元素”可以有下列形式:

          <cache 
              usage="transactional|read-write|nonstrict-read-write|read-only"  (1)
          />
          (1)

          usage說明了緩存的策略: transactionalread-writenonstrict-read-writeread-only

          另外(首選?), 你可以在hibernate.cfg.xml中指定<class-cache><collection-cache> 元素。

          這里的usage 屬性指明了緩存并發(fā)策略(cache concurrency strategy)

          20.2.2. 策略:只讀緩存(Strategy: read only)

          如果你的應用程序只需讀取一個持久化類的實例,而無需對其修改, 那么就可以對其進行只讀 緩存。這是最簡單,也是實用性最好的方法。甚至在集群中,它也能完美地運作。

          <class name="eg.Immutable" mutable="false">
              <cache usage="read-only"/>
              ....
          </class>

          20.2.3.  策略:讀/寫緩存(Strategy: read/write)

          如果應用程序需要更新數(shù)據,那么使用讀/寫緩存 比較合適。 如果應用程序要求“序列化事務”的隔離級別(serializable transaction isolation level),那么就決不能使用這種緩存策略。 如果在JTA環(huán)境中使用緩存,你必須指定hibernate.transaction.manager_lookup_class屬性的值, 通過它,Hibernate才能知道該應用程序中JTA的TransactionManager的具體策略。 在其它環(huán)境中,你必須保證在Session.close()、或Session.disconnect()調用前, 整個事務已經結束。 如果你想在集群環(huán)境中使用此策略,你必須保證底層的緩存實現(xiàn)支持鎖定(locking)。Hibernate內置的緩存策略并不支持鎖定功能。

          <class name="eg.Cat" .... >
              <cache usage="read-write"/>
              ....
              <set name="kittens" ... >
                  <cache usage="read-write"/>
                  ....
              </set>
          </class>

          20.2.4.  策略:非嚴格讀/寫緩存(Strategy: nonstrict read/write)

          如果應用程序只偶爾需要更新數(shù)據(也就是說,兩個事務同時更新同一記錄的情況很不常見),也不需要十分嚴格的事務隔離, 那么比較適合使用非嚴格讀/寫緩存策略。如果在JTA環(huán)境中使用該策略, 你必須為其指定hibernate.transaction.manager_lookup_class屬性的值, 在其它環(huán)境中,你必須保證在Session.close()、或Session.disconnect()調用前, 整個事務已經結束

          -------------------------------------------------------------------------
          在jBPM 中使用不少這樣的非嚴格讀/寫緩存的處理:
          <?xml version="1.0"?>

          <!DOCTYPE hibernate-mapping PUBLIC
              "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
              "

          <hibernate-mapping default-access="field">

            <class name="org.jbpm.context.def.VariableAccess"
                   table="JBPM_VARIABLEACCESS"
                   lazy="false">
              <cache usage="nonstrict-read-write"/>
              <id name="id" column="ID_"><generator class="native" /></id>
             
              <property name="variableName" column="VARIABLENAME_" />
              <property name="access" column="ACCESS_" />
              <property name="mappedName" column="MAPPEDNAME_" />
            </class>

          </hibernate-mapping>

          它的ehcache.xml 是這樣配置的:
          <ehcache>
           <defaultCache
                  maxElementsInMemory="100000"
                  eternal="true"
                  overflowToDisk="false"
                  diskPersistent="false"
                  />
          </ehcache>


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


          網站導航:
           
          主站蜘蛛池模板: 天全县| 酉阳| 日土县| 定日县| 论坛| 龙南县| 永济市| 建昌县| 涡阳县| 昌平区| 丘北县| 宿迁市| 崇信县| 淄博市| 阳高县| 内江市| 陵川县| 大足县| 阿拉善右旗| 博客| 靖宇县| 永川市| 宁城县| 余江县| 视频| 怀来县| 博兴县| 博白县| 哈密市| 抚宁县| 苗栗县| 尚志市| 德安县| 吉水县| 凌源市| 志丹县| 竹山县| 兴国县| 嘉黎县| 诸城市| 疏附县|