论坛首页 Java企业应用论坛

hibernate 3.3采用新的缓存方法

浏览 8512 次
精华帖 (0) :: 良好帖 (1) :: 新手帖 (5) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-11-25   最后修改:2008-11-25
今天查看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}).
   发表时间:2008-11-25  
hibernate3.3使用HQL做批量更新时二级缓存做不做响应的更新?
0 请登录后投票
   发表时间:2008-11-25   最后修改: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;
}

0 请登录后投票
   发表时间:2008-11-25  
ququzone 写道
hibernate3.3使用HQL做批量更新时二级缓存做不做响应的更新?

应该会清除所有缓存吧
可以去看看源码
0 请登录后投票
   发表时间:2008-11-26  
xly_971223 写道
ququzone 写道
hibernate3.3使用HQL做批量更新时二级缓存做不做响应的更新?

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

为什么不是来维护数据类
比如说修改好了然后接着进行二级缓存的维护,读取最新的数据
0 请登录后投票
   发表时间:2008-11-26  
新东东,新气象。

看其接口和实现,表现形式上的确有很大变化,不过其思想和以前的 CacheProvider + Cache还是一样的。
0 请登录后投票
   发表时间:2008-11-30  
恩,确实对二级缓存做了改进。原有的接口只是个简单的应急,这次估计也只能算是个过渡。不过应该是比原来的好点了吧,有机会再好好研究下源码
0 请登录后投票
   发表时间:2008-12-23  
还没有机会看源码这一块的
0 请登录后投票
   发表时间:2008-12-23  
xly_971223 写道

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

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

Query一致就允许setCacheRegion...
0 请登录后投票
   发表时间:2008-12-23  
郁闷我怎么看不明白了;  楼主的那一个张学友的照片很帅 !
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics