`
xly_971223
  • 浏览: 1283994 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

hibernate 3.3采用新的缓存方法

    博客分类:
  • java
阅读更多
今天查看hibernate cache接口时 svn了hibernate3.3的源码
打开CacheProvider类一看 居然给 @deprecated
真是大块人心
早就对hibernate的二级缓存和查询缓存不爽

只能按照实体配置 不能针对某条查询语句设置

3.3的提供了两个接口 Region  RegionFactory 来代替 3.2中的Cache CacheProvider
看看RegionFactory 的实现吧
看看这几个方法名字是多么的让人激动
buildCollectionRegion  对集合的缓存 猜测是对一对多的集合进行配置的吧
buildQueryResultsRegion  查询缓存 自定义的查询 也可以有自己的region了
buildTimestampsRegion    给缓存设置过期时间吧 

英文不好 猜测的 英文好的可以翻译一下
在gg上搜索了一下hibernate RegionFactory 关键字 居然没搜索到
难道大家对个功能都不感冒

public interface RegionFactory {

	public void start(Settings settings, Properties properties) throws CacheException;
	
	public void stop();
	
	public boolean isMinimalPutsEnabledByDefault();

	public long nextTimestamp();

	public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException;

	public CollectionRegion buildCollectionRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException;

	public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) throws CacheException;

	public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) throws CacheException;
}


附上hibernate3.3 cache包里的说明
引用
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}).
分享到:
评论
12 楼 hantsy 2009-03-09  
二级缓存方法只在频繁读取而极少更新(甚至没有更新)的情况下有用。。。
如果是频繁更新的操作,使用它的话,只会降低性能。
11 楼 kjj 2009-01-11  
呵呵,希望楼主再接再厉,搞出一个instance 来 ,直接把原来的3.X 升级成3.3
10 楼 flyheh 2008-12-24  
能对查询和记录进行缓存,真是有点激动人心,谢谢LZ共享
9 楼 e4077wf 2008-12-23  
郁闷我怎么看不明白了;  楼主的那一个张学友的照片很帅 !
8 楼 nihongye 2008-12-23  
xly_971223 写道

早就对hibernate的二级缓存和查询缓存不爽

只能按照实体配置 不能针对某条查询语句设置

Query一致就允许setCacheRegion...
7 楼 darkjune 2008-12-23  
还没有机会看源码这一块的
6 楼 srdrm 2008-11-30  
恩,确实对二级缓存做了改进。原有的接口只是个简单的应急,这次估计也只能算是个过渡。不过应该是比原来的好点了吧,有机会再好好研究下源码
5 楼 raymond2006k 2008-11-26  
新东东,新气象。

看其接口和实现,表现形式上的确有很大变化,不过其思想和以前的 CacheProvider + Cache还是一样的。
4 楼 mosheo 2008-11-26  
xly_971223 写道
ququzone 写道
hibernate3.3使用HQL做批量更新时二级缓存做不做响应的更新?

应该会清除所有缓存吧
可以去看看源码

为什么不是来维护数据类
比如说修改好了然后接着进行二级缓存的维护,读取最新的数据
3 楼 xly_971223 2008-11-25  
ququzone 写道
hibernate3.3使用HQL做批量更新时二级缓存做不做响应的更新?

应该会清除所有缓存吧
可以去看看源码
2 楼 xly_971223 2008-11-25  

public interface GeneralDataRegion extends Region {

	/**
	 * Get an item from the cache.
	 *
	 * @param key The key of the item to be retrieved.
	 * @return the cached object or <tt>null</tt>
	 * @throws CacheException Indicates a problem accessing the item or region.
	 */
	public Object get(Object key) throws CacheException;

	/**
	 * Put an item into the cache.
	 *
	 * @param key The key under which to cache the item.
	 * @param value The item to cache.
	 * @throws CacheException Indicates a problem accessing the region.
	 */
	public void put(Object key, Object value) throws CacheException;

	/**
	 * Evict an item from the cache immediately (without regard for transaction
	 * isolation).
	 *
	 * @param key The key of the item to remove
	 * @throws CacheException Indicates a problem accessing the item or region.
	 */
	public void evict(Object key) throws CacheException;

	/**
	 * Evict all contents of this particular cache region (without regard for transaction
	 * isolation).
	 *
	 * @throws CacheException Indicates problem accessing the region.
	 */
	public void evictAll() throws CacheException;
}

1 楼 ququzone 2008-11-25  
hibernate3.3使用HQL做批量更新时二级缓存做不做响应的更新?

相关推荐

    Struts2 + Spring 2.5 + Hibernate 3.3 整合(实际使用项目,version1)

    此项目整合了目前主流和最前源的web开发技术:采用ehcache实现二级缓存(包含查询缓存);用sf4j及logback(log4j的升级版)记录日志;proxool(据说是dbcp和c3p0三者中最优秀的)做连接池;使用jquery的ajax实现仿...

    Struts2.1.6+Spring2.5.6+Hibernate3.3.2整合包

    同时,它改进了性能和缓存策略,增强了查询语言HQL(Hibernate Query Language)的功能,提供了更强大的数据检索能力。 在整合这三个框架时,通常会采用Spring作为应用的容器,管理Struts2和Hibernate的实例。...

    hibernate缓存机制

    在Hibernate 3.3版之后,推荐使用基于RegionFactory的缓存机制,而不是基于CacheProvider的老方法。然而,对于旧版本的理解仍然是选择合适缓存策略的基础。 总之,Hibernate的缓存机制通过减少数据库访问频率,提升...

    精通 Hibernate:Java 对象持久化技术详解(第2版).part2

     22.4 管理Hibernate的第二级缓存  22.4.1 配置进程范围内的第二级缓存  22.4.2 配置集群范围内的第二级缓存  22.4.3 在应用程序中管理第二级缓存  22.4.4 Session与第二级缓存的交互模式  22.5 运行本章的...

    Hibernate中文文档

    为了提高应用程序性能,Hibernate 内置了缓存机制,分为一级缓存和二级缓存。 - **一级缓存**:默认启用,用于 Session 内部,当 Session 关闭时清空。 - **二级缓存**:可选配置,用于不同 Session 间共享数据,可...

    ASP.NET MVC4 + NHibernate3.3 DEMO

    MVC4引入了若干新特性,如移动支持、改进的模板选择机制、新的路由库等,使得开发者可以更加灵活地构建应用。 NHibernate是.NET平台上的一款开源ORM框架,它允许开发人员用面向对象的方式处理数据库操作,而无需...

    iBATIS缓存介绍

    缓存能够存放的最大元素数量是一个重要的参数,当缓存达到最大容量时,需要采用缓存更新策略进行数据的替换或清理。 **1.5 缓存更新策略** - **1.5.1 FIFO (First In First Out)**:最早进入缓存的数据将在缓存...

    Struts+Spring+Hibernate框架搭建

    3. 配置Hibernate属性,如缓存策略、方言等; 4. 注册实体类。 ##### 3.4 配置事务 事务管理是持久层开发中的一个重要方面。Spring提供了一种简单的方式来进行事务管理,即使用`TransactionManager`。 配置事务的...

    精通 Hibernate:Java 对象持久化技术详解(第2版).part4

     22.4 管理Hibernate的第二级缓存  22.4.1 配置进程范围内的第二级缓存  22.4.2 配置集群范围内的第二级缓存  22.4.3 在应用程序中管理第二级缓存  22.4.4 Session与第二级缓存的交互模式  22.5 运行本章的...

    精通 Hibernate:Java 对象持久化技术详解(第2版).part3

     22.4 管理Hibernate的第二级缓存  22.4.1 配置进程范围内的第二级缓存  22.4.2 配置集群范围内的第二级缓存  22.4.3 在应用程序中管理第二级缓存  22.4.4 Session与第二级缓存的交互模式  22.5 运行本章的...

    精通 Hibernate:Java 对象持久化技术详解(第2版).part1.rar

     22.4 管理Hibernate的第二级缓存  22.4.1 配置进程范围内的第二级缓存  22.4.2 配置集群范围内的第二级缓存  22.4.3 在应用程序中管理第二级缓存  22.4.4 Session与第二级缓存的交互模式  22.5 运行本章的...

    Hibernate Reference Documentation(Hibernate参考手册)

    - **模块化设计**:Hibernate采用了模块化的架构设计,便于扩展和维护。 - **JMX集成**:提供了对Java管理扩展的支持,便于监控和管理Hibernate实例。 - **JCA支持**:通过资源适配器提供与企业级应用服务器的集成。...

    Struts2.1.6+Hibernate3.3.1+Spring2.5.6整合jar包.zip

    此外,Hibernate还支持二级缓存,提高了数据访问效率。 Spring2.5.6是Spring框架的一个经典版本,它强化了依赖注入,使得对象的创建和配置更加灵活,降低了组件之间的耦合。同时,Spring2.5.6加强了AOP支持,可以...

    Memchached数据库缓存缓存思路

    舍得网采用基于Hibernate的高效数据库缓存系统,该系统集成了Memcached的分布式特性,成功支撑起日均1亿PV的访问量。通过精细的设计和实现,不仅保证了系统的稳定性和性能,还大幅降低了数据库的压力。 - **技术...

    hibernate教程

    - **自定义缓存提供者**:可以使用第三方缓存实现(如 Ehcache)作为 Hibernate 的二级缓存。 - **事务策略配置**:配置 Hibernate 如何处理事务边界。 - **JNDI 绑定 SessionFactory**:在容器环境中,可以将 ...

    Hibernate授课指导

    下载最新的Hibernate版本,本课程推荐使用版本3.3。 - **集成环境**: - 创建Java项目。 - 添加必要的jar包:将`hibernate3.jar`和`lib/required`目录下的所有jar包添加到项目中,并确保包含了数据库驱动的jar包。...

    Hibernate_Struts_Spring整合技术在电子政务中的应用.pdf

    通过配置文件如`hibernate.properties`等,开发者可以灵活地设置Hibernate的行为,如缓存策略、连接池管理等。 #### 四、结论 综上所述,HSS技术在电子政务系统中的应用具有明显的优势,不仅可以提高系统的整体...

Global site tag (gtag.js) - Google Analytics