`

探索 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




  • 大小: 31.4 KB
分享到:
评论

相关推荐

    配置Spring+hibernate使用ehcache作为second-levelcache.docx

    " Spring+Hibernate 使用 Ehcache 作为 Second-Level Cache" Spring 和 Hibernate 是 Java Web 应用程序开发中两个非常重要的技术栈。Spring 是一个轻量级的控制反转(IoC)容器,提供了一个框架来管理 Java 对象...

    Hibernate 2nd-level cache: JBoss Caching 配置与注意事项

    &lt;property name="hibernate.cache.use_second_level_cache"&gt;true &lt;property name="hibernate.cache.region.factory_class"&gt;org.hibernate.cache.jbc2.JBossCacheRegionFactory ``` 3. 配置JBoss Caching:创建一个...

    hibernate-jpa-2.1-api 1.0.0.Final API

    12. **二级缓存(Second-Level Cache)**:提高性能,缓存已加载的实体,减少对数据库的访问。 13. **实体图形(Entity Graphs)**:在查询时控制哪些关联应被加载,有助于避免N+1查询问题。 以上知识点构成了...

    第29讲--为Spring集成的Hibernate配置二级缓存

    &lt;property name="hibernate.cache.use_second_level_cache"&gt;true &lt;property name="hibernate.cache.region.factory_class"&gt;org.hibernate.cache.ehcache.EhCacheRegionFactory ``` 接下来,我们要为想要缓存的实体...

    hibernate-release-5.0.7.Final.zip官方

    &lt;property name="hibernate.cache.use_second_level_cache"&gt;true &lt;property name="hibernate.cache.use_query_cache"&gt;true &lt;property name="hibernate.ejb.entitymanager_factory_name"&gt;hibernateSessionFactory ```...

    hibernate4.0使用二级缓存jar包

    &lt;property name="hibernate.cache.use_second_level_cache"&gt;true &lt;!-- 查询的二级缓存配置 --&gt; &lt;property name="hibernate.cache.use_query_cache"&gt;true &lt;property name="cache.provider_class"&gt;org....

    hibernate需要用到的core及annotations jar包

    6. Second-Level Cache和Query Cache: 为了提高性能,Hibernate支持二级缓存和查询缓存。二级缓存可以缓存已经加载过的对象,减少数据库访问;查询缓存则能存储查询结果,避免重复计算。 7. Callback事件: ...

    hibernate_cache_level_1

    &lt;property name="hibernate.cache.use_second_level_cache"&gt;true &lt;property name="hibernate.cache.use_query_cache"&gt;true ``` 接下来,我们需要在实体类上添加`@Cacheable`注解,或者在映射文件中设置 `&lt;cache ...

    hibernate-distribution-3.6.2.Final-dist jar包

    8. **第二级缓存(Second Level Cache)**:Hibernate支持缓存机制,提高数据访问效率。第二级缓存可以存储实体对象,跨会话共享,减少对数据库的直接访问。 9. **Criteria API与Query API**:除了HQL,Hibernate还...

    hibernate caching

    #### 三、二级缓存策略 (Second-Level Cache Strategies) 二级缓存策略是指在 Hibernate 中配置和管理二级缓存的方式。常见的策略包括: - **Read-only (只读)**:该模式下,一旦数据加载到缓存后就不会再发生变化...

    hibernate--5.Hibernate配置文件详解-2

    &lt;property name="hibernate.cache.use_second_level_cache"&gt;true &lt;property name="hibernate.cache.region.factory_class"&gt;org.hibernate.cache.ehcache.EhCacheRegionFactory ``` 接下来是实体类的映射信息。虽然...

    hibernate_release_5.0.12.zip

    第二级缓存(Second-Level Cache)和查询缓存(Query Cache)得到了改善,可以减少数据库的访问次数,提高系统响应速度。此外,这个版本还优化了事务处理和并发控制,为高并发场景提供了更好的支持。 对于分布式...

    grails-redis-hibernate-cache:Grails 与 Redis 的集成作为 Hibernate 二级缓存的后端

    Grails Redis Hibernate 二级缓存 这个插件简化了 Grails Hibernate 2nd Level 缓存和 Redis 之间的集成。 安装 要安装,您需要将插件添加到 BuildConfig.... use_second_level_cache = true cache . use_query_cac

    hibernate_cache_level_2.rar_java_staredb4u

    &lt;property name="hibernate.cache.use_second_level_cache"&gt;true &lt;property name="hibernate.cache.region.factory_class"&gt;org.hibernate.cache.ehcache.EhCacheRegionFactory ``` 接下来,我们需要为特定的实体类...

    reference manual for hibernate 3.x.rar

    9. **Second-Level Cache**:学习二级缓存(Second-Level Cache)的配置和使用,以提升应用程序性能。 10. **性能优化**:掌握如何优化Hibernate应用,包括批处理、延迟加载(Lazy Loading)、预加载(Eager ...

    Hibernate 4.4.1最终发布版本

    3. **Second-Level Cache**:此版本优化了二级缓存的使用,提升了数据访问的效率。开发者可以通过注解或者配置文件启用缓存,并选择合适的缓存提供者,如Ehcache或Infinispan。 4. **JPA 2.1兼容性**:Hibernate ...

    hibernate4.3.6

    二级缓存(Second Level Cache)允许共享对象实例,提高数据读取速度。同时,这个版本还优化了事务管理,提供更细粒度的控制,使得并发性能得到提升。 在实际应用中,我们经常使用SessionFactory创建Session对象,...

    Hibernate4 环境搭建

    &lt;property name="hibernate.cache.use_second_level_cache"&gt;true &lt;property name="hibernate.cache.use_query_cache"&gt;true &lt;!-- Hibernate4 Ehcache 配置 --&gt; &lt;property name="hibernate.cache.region.factory_...

    hibernate cache

    - **配置**:通过 `hibernate.cache.use_second_level_cache` 配置启用,然后选择合适的提供者。 - **分区**:缓存数据可以按类或特定查询进行分区,以便更高效地管理。 - **过期策略**:可通过设置缓存的生存时间或...

Global site tag (gtag.js) - Google Analytics