|
|||||||||
| Home >> All >> org >> hibernate >> [ cache overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.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.
- DELETES :
lock(java.lang.Object, java.lang.Object)55 ->evict(java.lang.Object)55 ->release(java.lang.Object, org.hibernate.cache.CacheConcurrencyStrategy.SoftLock)55 - UPDATES :
lock(java.lang.Object, java.lang.Object)55 ->update(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)55 ->afterUpdate(java.lang.Object, java.lang.Object, java.lang.Object, org.hibernate.cache.CacheConcurrencyStrategy.SoftLock)55 - INSERTS :
insert(java.lang.Object, java.lang.Object, java.lang.Object)55 ->afterInsert(java.lang.Object, java.lang.Object, java.lang.Object)55
lock(java.lang.Object, java.lang.Object) 55 -> evict(java.lang.Object) 55 -> release(java.lang.Object, org.hibernate.cache.CacheConcurrencyStrategy.SoftLock) 55
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.
| Nested Class Summary | |
static interface |
CacheConcurrencyStrategy.SoftLock
Marker interface, denoting a client-visible "soft lock" on a cached item. |
| Method Summary | |
boolean |
afterInsert(java.lang.Object key,
java.lang.Object value,
java.lang.Object version)
Called after an item has been inserted (after the transaction completes), instead of calling release(). |
boolean |
afterUpdate(java.lang.Object key,
java.lang.Object value,
java.lang.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(java.lang.Object key)
Called after an item has become stale (before the transaction completes). |
java.lang.Object |
get(java.lang.Object key,
long txTimestamp)
Attempt to retrieve an object from the cache. |
Cache |
getCache()
Get the wrapped cache implementation |
java.lang.String |
getRegionName()
Get the cache region name |
boolean |
insert(java.lang.Object key,
java.lang.Object value,
java.lang.Object currentVersion)
Called after an item has been inserted (before the transaction completes), instead of calling evict(). |
CacheConcurrencyStrategy.SoftLock |
lock(java.lang.Object key,
java.lang.Object version)
We are going to attempt to update/delete the keyed object. |
boolean |
put(java.lang.Object key,
java.lang.Object value,
long txTimestamp,
java.lang.Object version,
java.util.Comparator versionComparator,
boolean minimalPut)
Attempt to cache an object, after loading from the database. |
void |
release(java.lang.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(java.lang.Object key)
Evict an item from the cache immediately (without regard for transaction isolation). |
void |
setCache(Cache cache)
Set the underlying cache implementation. |
boolean |
update(java.lang.Object key,
java.lang.Object value,
java.lang.Object currentVersion,
java.lang.Object previousVersion)
Called after an item has been updated (before the transaction completes), instead of calling evict(). |
| Method Detail |
get
public java.lang.Object get(java.lang.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.
put
public boolean put(java.lang.Object key, java.lang.Object value, long txTimestamp, java.lang.Object version, java.util.Comparator versionComparator, boolean minimalPut) throws CacheException
- Attempt to cache an object, after loading from the database.
lock
public CacheConcurrencyStrategy.SoftLock lock(java.lang.Object key, java.lang.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.
evict
public void evict(java.lang.Object key) throws CacheException
- Called after an item has become stale (before the transaction completes).
This method is used by "synchronous" concurrency strategies.
update
public boolean update(java.lang.Object key, java.lang.Object value, java.lang.Object currentVersion, java.lang.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.
insert
public boolean insert(java.lang.Object key, java.lang.Object value, java.lang.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.
release
public void release(java.lang.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.
afterUpdate
public boolean afterUpdate(java.lang.Object key, java.lang.Object value, java.lang.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.
afterInsert
public boolean afterInsert(java.lang.Object key, java.lang.Object value, java.lang.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.
remove
public void remove(java.lang.Object key) throws CacheException
- Evict an item from the cache immediately (without regard for transaction
isolation).
clear
public void clear()
throws CacheException
- Evict all items from the cache immediately.
destroy
public void destroy()
- Clean up all resources.
setCache
public void setCache(Cache cache)
- Set the underlying cache implementation.
getRegionName
public java.lang.String getRegionName()
- Get the cache region name
getCache
public Cache getCache()
- Get the wrapped cache implementation
|
|||||||||
| Home >> All >> org >> hibernate >> [ cache overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC