二级缓存

hibernate 二级缓存;

* 二级缓存 sessionFactory级的缓存 session之间可以共享(可插拔)
* 二级缓存的环境搭配如下:

1、拷贝hibernate包内etc文件夹内的\ehcache.xml目录(在src下加入ehcache.xml) 删除不必要的内容 只留下

<diskStore path="java.io.tmpdir"/> //溢出后存放的目录例如:<diskStore path="d:\\cache"/>

<defaultCache
maxElementsInMemory="10000" //在缓存区最大元素 默认为10000;
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true" //溢出到硬盘;
/>

<cache name="pojo.Items" //要管理的类,如果有多个类需要管理的话 可以复制创建多个cache;
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true" //溢出到硬盘;
/>


2、在hibernate.cfg.xml中添加如下:

<property name="hibernate.cache.use_second_level_cache">true</property> //为true的时候是启用二级缓存
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> //指明提供商
<class-cache class="pojo.User" usage="read-only"/> //管理二级缓存的类,如果有多个类需要管理 可创建多个;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值