- 论坛徽章:
- 0
|
2.映射文件:
Student.hbm.xml
<class name="com.sxt.hibernate.cache.entity.Student" table="sxt_hibernate_student">
<!-- 指定本类的对象使用二级缓存(这也可以放在hibernate.cfg.xml中统一指定) -->
<!--
<cache usage="read-only"/>
-->
<id name="id" length="4">
<generator class="native"></generator>
</id>
<property name="name" length="10"></property>
</class>
3. 二级缓存配置文件:
ehcache.xml
<ehcache>
<!-- 当二级缓存溢出时,对象保存的临时磁盘路径 -->
<diskStore path="java.io.tmpdir"/>
<!--name="sampleCache2" 缓存名字
maxElementsInMemory="1000" 缓存里可存放的最大对象数.
eternal="true" 缓存对象是否永久有效(true表示是).
timeToIdleSeconds="120" 对象在缓存中存活的空闲时间,即空闲多久它就失效,单位是秒.
timeToLiveSeconds="120" 对象在缓存中存活的时间,单位是秒.
overflowToDisk="true" 当缓存溢出时,对象是否保存到磁盘上.保存的磁盘路径由<diskStore>中的path指定.
-->
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
</ehcache> |
|