Package org.hibernate.cache
Interface CacheConcurrencyStrategy
- All Known Implementing Classes:
NonstrictReadWriteCache,ReadOnlyCache,ReadWriteCache,TransactionalCache
public interface CacheConcurrencyStrategy
Deprecated.
As of 3.3; see for details.
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.
- DELETES :
lock(java.lang.Object, java.lang.Object)->evict(java.lang.Object)->release(java.lang.Object, org.hibernate.cache.access.SoftLock) - UPDATES :
lock(java.lang.Object, java.lang.Object)->update(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)->afterUpdate(java.lang.Object, java.lang.Object, java.lang.Object, org.hibernate.cache.access.SoftLock) - INSERTS :
insert(java.lang.Object, java.lang.Object, java.lang.Object)->afterInsert(java.lang.Object, java.lang.Object, java.lang.Object)
lock(java.lang.Object, java.lang.Object) -> evict(java.lang.Object) -> release(java.lang.Object, org.hibernate.cache.access.SoftLock)
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 nontransactional 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.
Note that query result caching does not go through a concurrency strategy; they
are managed directly against the underlying cache regions.-
Method Summary
Modifier and TypeMethodDescriptionbooleanafterInsert(Object key, Object value, Object version) Deprecated.Called after an item has been inserted (after the transaction completes), instead of calling release().booleanafterUpdate(Object key, Object value, Object version, SoftLock lock) Deprecated.Called after an item has been updated (after the transaction completes), instead of calling release().voidclear()Deprecated.Evict all items from the cache immediately.voiddestroy()Deprecated.Clean up all resources.voidDeprecated.Called after an item has become stale (before the transaction completes).Deprecated.Attempt to retrieve an object from the cache.getCache()Deprecated.Get the wrapped cache implementationDeprecated.Get the cache region namebooleanDeprecated.Called after an item has been inserted (before the transaction completes), instead of calling evict().Deprecated.We are going to attempt to update/delete the keyed object.booleanput(Object key, Object value, long txTimestamp, Object version, Comparator versionComparator, boolean minimalPut) Deprecated.Attempt to cache an object, after loading from the database.voidDeprecated.Called when we have finished the attempted update/delete (which may or may not have been successful), after transaction completion.voidDeprecated.Evict an item from the cache immediately (without regard for transaction isolation).voidDeprecated.Set the underlying cache implementation.booleanDeprecated.Called after an item has been updated (before the transaction completes), instead of calling evict().
-
Method Details
-
get
Deprecated.Attempt to retrieve an object from the cache. Mainly used in attempting to resolve entities/collections from the second level cache.- Parameters:
key-txTimestamp- a timestamp prior to the transaction start time- Returns:
- the cached object or null
- Throws:
CacheException
-
put
boolean put(Object key, Object value, long txTimestamp, Object version, Comparator versionComparator, boolean minimalPut) throws CacheException Deprecated.Attempt to cache an object, after loading from the database.- Parameters:
key-value-txTimestamp- a timestamp prior to the transaction start timeversion- the item version numberversionComparator- a comparator used to compare version numbersminimalPut- indicates that the cache should avoid a put is the item is already cached- Returns:
- true if the object was successfully cached
- Throws:
CacheException
-
lock
Deprecated.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
Deprecated.Called after an item has become stale (before the transaction completes). This method is used by "synchronous" concurrency strategies.- Throws:
CacheException
-
update
boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException Deprecated.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
Deprecated.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
Deprecated.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
Deprecated.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
Deprecated.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
Deprecated.Evict an item from the cache immediately (without regard for transaction isolation).- Parameters:
key-- Throws:
CacheException
-
clear
Deprecated.Evict all items from the cache immediately.- Throws:
CacheException
-
destroy
void destroy()Deprecated.Clean up all resources. -
setCache
Deprecated.Set the underlying cache implementation.- Parameters:
cache-
-
getRegionName
String getRegionName()Deprecated.Get the cache region name -
getCache
Cache getCache()Deprecated.Get the wrapped cache implementation
-