|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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 |
public Object get(Object key, long txTimestamp) throws CacheException
key
- txTimestamp
- a timestamp prior to the transaction start time
CacheException
public boolean put(Object key, Object value, long txTimestamp, Object version, Comparator versionComparator) throws CacheException
key
- value
- txTimestamp
- a timestamp prior to the transaction start timeversion
- the version number of the object we are puttingversionComparator
- a Comparator to be used to compare version numbers
CacheException
public CacheConcurrencyStrategy.SoftLock lock(Object key, Object version) throws CacheException
key
- version
-
CacheException
public void evict(Object key) throws CacheException
CacheException
public void update(Object key, Object value) throws CacheException
CacheException
public void insert(Object key, Object value) throws CacheException
CacheException
public void release(Object key, CacheConcurrencyStrategy.SoftLock lock) throws CacheException
key
-
CacheException
public void afterUpdate(Object key, Object value, Object version, CacheConcurrencyStrategy.SoftLock lock) throws CacheException
CacheException
public void afterInsert(Object key, Object value, Object version) throws CacheException
CacheException
public void remove(Object key) throws CacheException
key
-
CacheException
public void clear() throws CacheException
CacheException
public void destroy()
public void setCache(Cache cache)
cache
- public void setMinimalPuts(boolean minimalPuts) throws HibernateException
HibernateException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |