探索 Hibernate 3.3 second-level cache


自 Hibernate 3.3 开始,二级缓存机制发生重大变化,官方文档中尚未见更新(2008-12-10),仅以此文抛砖引玉!


Hibernate 3.3.0.GA has been released.

A few changes from 3.2 worth noting:

   1. Migration to a Maven-based build
   2. Splitting of the project into modular jars. This allows users to easily see and minimize dependencies.
   3. Redesigned second-level caching SPI
   4. Integration with JBossCache 2.x as a second level cache provider.

/**
 * Support for pluggable caches.
 *
 * @author Gavin King
 * @deprecated As of 3.3; see <a href="package.html"/> for details.
 */
public interface CacheProvider {...}


This package defines APIs/SPIs and implementations for the Hibernate second-level cache.

The legacy (and now deprecated) approach to caching is defined by the {@link org.hibernate.cache.CacheProvider} and {@link org.hibernate.cache.Cache} interfaces as well as the {@link org.hibernate.cache.CacheConcurrencyStrategy} interface along with the various implementations of all these interfaces. In that scheme, a {@link org.hibernate.cache.CacheProvider} defined how to configure and perform lifecycle operations in regards to a particular underlying caching library; it also defined how to build {@link org.hibernate.cache.Cache} instances which in turn defined how to access the "regions" of the underlying cache instance. For entity and collection data cache regions, {@link org.hibernate.cache.CacheConcurrencyStrategy} wrapped access to those cache regions to apply transactional/concurrent access semantics.

The improved approach is based on {@link org.hibernate.cache.RegionFactory}, the various {@link org.hibernate.cache.Region} specializations and the two access strategies contracts ({@link org.hibernate.cache.access.EntityRegionAccessStrategy} and {@link org.hibernate.cache.access.CollectionRegionAccessStrategy}). The general approach here is that {@link org.hibernate.cache.RegionFactory} defined how to configure and perform lifecycle operations in regards to a particular underlying caching library (or libraries). {@link org.hibernate.cache.RegionFactory} also defines how to build specialized {@link org.hibernate.cache.Region} instances based on the type of data we will be storing in that given region. The fact that {@link org.hibernate.cache.RegionFactory} is asked to build specialized regions (as opposed to just general access) is the first improvement over the legacy scheme. The second improvement is the fact that the regions (well the ones like entity and collection regions that are responsible for storing {@link org.hibernate.cache.TransactionalDataRegion transactional} data) are asked to build their own access strategies (see {@link org.hibernate.cache.EntityRegion#buildAccessStrategy} and {@link org.hibernate.cache.CollectionRegion#buildAccessStrategy}). 


This is all looks a bit complex, so let's show what happens if you just configure the defaults, with query caching enabled:

hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory




To be continued


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值