站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Hibernate 2.1.8 正式版 API 英文文档

CacheConcurrencyStrategy (Hibernate API Documentation) - Hibernate 2.1.8 正式版 API 英文文档


net.sf.hibernate.cache
Interface CacheConcurrencyStrategy

All Known Implementing Classes:
NonstrictReadWriteCache, ReadOnlyCache, ReadWriteCache, TransactionalCache

public interface CacheConcurrencyStrategy

Implementors manage transactional access to cached data. Transactions pass in a timestamp indicating transaction start time. Two different implementation patterns are provided for. A transaction-aware cache implementation might be wrapped by a "synchronous" concurrency strategy, where updates to the cache are written to the cache inside the transaction. A non transaction-aware cache would be wrapped by an "asynchronous" concurrency strategy, where items are merely "soft locked" during the transaction and then updated during the "after transaction completion" phase. The soft lock is not an actual lock on the database row - only upon the cached representation of the item.

For the client, update lifecycles are: lock->evict->release, lock->update->afterUpdate, insert->afterInsert.

Note that, for an asynchronous cache, cache invalidation must be a two step process (lock->release, or lock-afterUpdate), since this is the only way to guarantee consistency with the database for a nontransaction cache implementation. For a synchronous cache, cache invalidation is a single step process (evict, or update). Hence, this interface defines a three step process, to cater for both models.


Nested Class Summary
static interface CacheConcurrencyStrategy.SoftLock
          Marker interface, denoting a client-visible "soft lock" on a cached item.
 
Method Summary
 void afterInsert(Object key, Object value, Object version)
          Called after an item has been inserted (after the transaction completes), instead of calling release().
 void afterUpdate(Object key, Object value, Object version, CacheConcurrencyStrategy.SoftLock lock)
          Called after an item has been updated (after the transaction completes), instead of calling release().
 void clear()
          Evict all items from the cache immediately.
 void destroy()
          Clean up all resources.
 void evict(Object key)
          Called after an item has become stale (before the transaction completes).
 Object get(Object key, long txTimestamp)
          Attempt to retrieve an object from the cache.
 void insert(Object key, Object value)
          Called after an item has been inserted (before the transaction completes), instead of calling evict().
 CacheConcurrencyStrategy.SoftLock lock(Object key, Object version)
          We are going to attempt to update/delete the keyed object.
 boolean put(Object key, Object value, long txTimestamp, Object version, Comparator versionComparator)
          Attempt to cache an object, after loading from the database.
 void release(Object key, CacheConcurrencyStrategy.SoftLock lock)
          Called when we have finished the attempted update/delete (which may or may not have been successful), after transaction completion.
 void remove(Object key)
          Evict an item from the cache immediately (without regard for transaction isolation).
 void setCache(Cache cache)
          Set the underlying cache implementation.
 void setMinimalPuts(boolean minimalPuts)
          Enable "minimal puts" mode for this cache
 void update(Object key, Object value)
          Called after an item has been updated (before the transaction completes), instead of calling evict().
 

Method Detail

get

public Object get(Object key,
                  long txTimestamp)
           throws CacheException
Attempt to retrieve an object from the cache.

Parameters:
key -
txTimestamp - a timestamp prior to the transaction start time
Returns:
the cached object or null
Throws:
CacheException

put

public boolean put(Object key,
                   Object value,
                   long txTimestamp,
                   Object version,
                   Comparator versionComparator)
            throws CacheException
Attempt to cache an object, after loading from the database.

Parameters:
key -
value -
txTimestamp - a timestamp prior to the transaction start time
version - the version number of the object we are putting
versionComparator - a Comparator to be used to compare version numbers
Returns:
true if the object was successfully cached
Throws:
CacheException

lock

public CacheConcurrencyStrategy.SoftLock lock(Object key,
                                              Object version)
                                       throws CacheException
We are going to attempt to update/delete the keyed object. This method is used by "asynchronous" concurrency strategies. The returned object must be passed back to release(), to release the lock. Concurrency strategies which do not support client-visible locks may silently return null.

Parameters:
key -
version -
Throws:
CacheException

evict

public void evict(Object key)
           throws CacheException
Called after an item has become stale (before the transaction completes). This method is used by "synchronous" concurrency strategies.

Throws:
CacheException

update

public void update(Object key,
                   Object value)
            throws CacheException
Called after an item has been updated (before the transaction completes), instead of calling evict(). This method is used by "synchronous" concurrency strategies.

Throws:
CacheException

insert

public void insert(Object key,
                   Object value)
            throws CacheException
Called after an item has been inserted (before the transaction completes), instead of calling evict(). This method is used by "synchronous" concurrency strategies.

Throws:
CacheException

release

public void release(Object key,
                    CacheConcurrencyStrategy.SoftLock lock)
             throws CacheException
Called when we have finished the attempted update/delete (which may or may not have been successful), after transaction completion. This method is used by "asynchronous" concurrency strategies.

Parameters:
key -
Throws:
CacheException

afterUpdate

public void afterUpdate(Object key,
                        Object value,
                        Object version,
                        CacheConcurrencyStrategy.SoftLock lock)
                 throws CacheException
Called after an item has been updated (after the transaction completes), instead of calling release(). This method is used by "asynchronous" concurrency strategies.

Throws:
CacheException

afterInsert

public void afterInsert(Object key,
                        Object value,
                        Object version)
                 throws CacheException
Called after an item has been inserted (after the transaction completes), instead of calling release(). This method is used by "asynchronous" concurrency strategies.

Throws:
CacheException

remove

public void remove(Object key)
            throws CacheException
Evict an item from the cache immediately (without regard for transaction isolation).

Parameters:
key -
Throws:
CacheException

clear

public void clear()
           throws CacheException
Evict all items from the cache immediately.

Throws:
CacheException

destroy

public void destroy()
Clean up all resources.


setCache

public void setCache(Cache cache)
Set the underlying cache implementation.

Parameters:
cache -

setMinimalPuts

public void setMinimalPuts(boolean minimalPuts)
                    throws HibernateException
Enable "minimal puts" mode for this cache

Throws:
HibernateException