Top Description Methods
org.hibernate.cache

public Interface CacheConcurrencyStrategy

Known Direct Implementers
org.hibernate.cache.NonstrictReadWriteCache, org.hibernate.cache.ReadOnlyCache, org.hibernate.cache.ReadWriteCache, org.hibernate.cache.TransactionalCache
Imports
java.util.Comparator, org.hibernate.cache.access.SoftLock

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.

In terms of entity caches, the expected call sequences are:

In terms of collection caches, all modification actions actually just invalidate the entry(s). The call sequence here is: lock -> evict -> release

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 TypeMethod and Description
public boolean
afterInsert(Object key, Object value, Object version)

Called after an item has been inserted (after the transaction completes), instead of calling release().

public boolean
afterUpdate(Object key, Object value, Object version, SoftLock lock)

Called after an item has been updated (after the transaction completes), instead of calling release().

public void
clear()

Evict all items from the cache immediately.

public void
destroy()

Clean up all resources.

public void
evict(Object key)

Called after an item has become stale (before the transaction completes).

public Object

Returns:

the cached object or null
get
(Object key, long
a timestamp prior to the transaction start time
txTimestamp
)

Attempt to retrieve an object from the cache.

public Cache
getCache()

Deprecated as a consequence of Cache being deprecated.
Get the wrapped cache implementation
public String
getRegionName()

Get the cache region name

public boolean
insert(Object key, Object value, Object currentVersion)

Called after an item has been inserted (before the transaction completes), instead of calling evict().

public SoftLock
lock(Object key, Object version)

We are going to attempt to update/delete the keyed object.

public boolean

Returns:

true if the object was successfully cached
put
(Object key, Object value, long
a timestamp prior to the transaction start time
txTimestamp
,
Object
the item version number
version
,
Comparator<T>
a comparator used to compare version numbers
versionComparator
,
boolean
indicates that the cache should avoid a put is the item is already cached
minimalPut
)

Attempt to cache an object, after loading from the database.

public void
release(Object key, SoftLock lock)

Called when we have finished the attempted update/delete (which may or may not have been successful), after transaction completion.

public void
remove(Object key)

Evict an item from the cache immediately (without regard for transaction isolation).

public void
setCache(Cache cache)

Deprecated as a consequence of Cache being deprecated.
Set the underlying cache implementation.
public boolean
update(Object key, Object value, Object currentVersion, Object previousVersion)

Called after an item has been updated (before the transaction completes), instead of calling evict().

Method Detail

afterInsertback to summary
public boolean 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.

afterUpdateback to summary
public boolean afterUpdate(Object key, Object value, Object version, 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.

clearback to summary
public void clear() throws CacheException

Evict all items from the cache immediately.

destroyback to summary
public void destroy()

Clean up all resources.

evictback to summary
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.

getback to summary
public Object get(Object key, long txTimestamp) throws CacheException

Attempt to retrieve an object from the cache. Mainly used in attempting to resolve entities/collections from the second level cache.

Parameters
txTimestamp:long

a timestamp prior to the transaction start time

Returns:Object

the cached object or null

getCacheback to summary
public Cache getCache()

Deprecated

as a consequence of Cache being deprecated. See corresponding docs for further information.

Get the wrapped cache implementation

getRegionNameback to summary
public String getRegionName()

Get the cache region name

insertback to summary
public boolean insert(Object key, Object value, Object currentVersion) 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.

lockback to summary
public 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.

putback to summary
public boolean put(Object key, Object value, long txTimestamp, Object version, Comparator<T> versionComparator, boolean minimalPut) throws CacheException

Attempt to cache an object, after loading from the database.

Parameters
txTimestamp:long

a timestamp prior to the transaction start time

version:Object

the item version number

versionComparator:Comparator<T>

a comparator used to compare version numbers

minimalPut:boolean

indicates that the cache should avoid a put is the item is already cached

Returns:boolean

true if the object was successfully cached

releaseback to summary
public void release(Object key, 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.

removeback to summary
public void remove(Object key) throws CacheException

Evict an item from the cache immediately (without regard for transaction isolation).

setCacheback to summary
public void setCache(Cache cache)

Deprecated

as a consequence of Cache being deprecated. See corresponding docs for further information.

Set the underlying cache implementation.

updateback to summary
public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) 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.