首页 > Web开发 > 详细

Hibernate Cache

时间:2015-10-27 15:13:29      阅读:318      评论:0      收藏:0      [点我收藏+]

1. First level Cache--Session.

Querying of same object multiple times within a same session will only call DB for once, the rest of times will use cache to retrieve.

Same to openSession()&getCurrentSession()

 

2. Second level Cache--SessionFactory.

Data that is good for second level cache:

1.limited set of data;

2. Rarely being modified;

3. Won‘t be access by multiple objects at the same time

Example:

user authorization info. User entries are limited.  load()&iterative() use secondary cache; list uses second level cache,however, query doesn‘t!!

 

When hibernate accesses data, it first check first level cache, then check second level cache if it‘s configured, then check DB.

Configuration:

1.add ehcache.xml

2.

<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class"> org.hibernate.cache.ehcache.EhCacheRegionFactory</property>

 

3. @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)  ----> use default cache

 

For query checking using second level:

<property name="cache.use_query_cache">true</property>

 

xx.createQuery().setCachable(true).list 

 

Hibernate Cache

原文:http://www.cnblogs.com/fifi043/p/4914164.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!