您的位置:首页 > 其它

Hibernate 二级缓存初步理解

2009-09-15 20:39 204 查看
这里使用的是OSCache作为Hibernate的二级缓存实现的

1 在Hibernate.cfg.xml中添加:“<property name="cache.use_second_level_cache">true</property >”(默认是true)

2 在Hibernate.cfg.xml中添加:“<property name="cache.provider_class">org.hibernate.cache.OSCacheProvider</property >”(检查有没有相应的Jar包)

3 在src中添加oscache.properties文件,修改cache.capacity = **.

4 如果你要对bean中的user类进行缓存,你有两种方式:

一种是:在Hibernate.cfg.xml中添加:“<class-cache class="cn.hyit.rbms.User" usage="read-only"/>”,其中usage跟你更新的频率有关,它有四个值:read-only(只读,不能修改类),read-write(读写,可以保证并发性),nonstrict-read-write(对更新没有严格的限制),transactional(可以实现缓存数据的回滚)。

还有一种是在User.hbm.xml中添加:“<cache usage="read-write"/>”
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: