- 論壇徽章:
- 0
|
2.映射文件:
Student.hbm.xml
<class name="com.sxt.hibernate.cache.entity.Student" table="sxt_hibernate_student">
<!-- 指定本類的對(duì)象使用二級(jí)緩存(這也可以放在hibernate.cfg.xml中統(tǒng)一指定) -->
<!--
<cache usage="read-only"/>
-->
<id name="id" length="4">
<generator class="native"></generator>
</id>
<property name="name" length="10"></property>
</class>
3. 二級(jí)緩存配置文件:
ehcache.xml
<ehcache>
<!-- 當(dāng)二級(jí)緩存溢出時(shí),對(duì)象保存的臨時(shí)磁盤路徑 -->
<diskStore path="java.io.tmpdir"/>
<!--name="sampleCache2" 緩存名字
maxElementsInMemory="1000" 緩存里可存放的最大對(duì)象數(shù).
eternal="true" 緩存對(duì)象是否永久有效(true表示是).
timeToIdleSeconds="120" 對(duì)象在緩存中存活的空閑時(shí)間,即空閑多久它就失效,單位是秒.
timeToLiveSeconds="120" 對(duì)象在緩存中存活的時(shí)間,單位是秒.
overflowToDisk="true" 當(dāng)緩存溢出時(shí),對(duì)象是否保存到磁盤上.保存的磁盤路徑由<diskStore>中的path指定.
-->
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
</ehcache> |
|