|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.alfresco.repo.cache.TransactionalCache
public class TransactionalCache
A 2-level cache that mainains both a transaction-local cache and wraps a non-transactional (shared) cache.
It uses the Ehcache Cache for it's per-transaction caches as these provide automatic size limitations, etc.
Instances of this class do not require a transaction. They will work directly with the shared cache when no transaction is present. There is virtually no overhead when running out-of-transaction.
The first phase of the commit ensures that any values written to the cache in the current transaction are not already superceded by values in the shared cache. In this case, the transaction is failed for concurrency reasons and will have to retry. The second phase occurs post-commit. We are sure that the transaction committed correctly, but things may have changed in the cache between the commit and post-commit. If this is the case, then the offending values are merely removed from the shared cache.
When the cache is cleared, a flag is set on the transaction.
The shared cache, instead of being cleared itself, is just ignored for the remainder
of the tranasaction. At the end of the transaction, if the flag is set, the
shared transaction is cleared before updates are added back to it.
Because there is a limited amount of space available to the in-transaction caches, when either of these becomes full, the cleared flag is set. This ensures that the shared cache will not have stale data in the event of the transaction-local caches dropping items. It is therefore important to size the transactional caches correctly.
| Nested Class Summary | |
|---|---|
static class |
TransactionalCache.NullValueMarker
Instances of this class are used to mark the shared cache null values for cases where new values are going to be inserted into it. |
| Constructor Summary | |
|---|---|
TransactionalCache()
Public constructor. |
|
| Method Summary | |
|---|---|
void |
afterCommit()
Merge the transactional caches into the shared cache |
void |
afterPropertiesSet()
Ensures that all properties have been set |
void |
afterRollback()
Transfers cache removals or clears. |
void |
beforeCommit(boolean readOnly)
NO-OP |
void |
beforeCompletion()
NO-OP |
void |
clear()
Clears out all the caches. |
boolean |
contains(java.io.Serializable key)
Checks the transactional removed and updated caches before checking the shared cache. |
boolean |
equals(java.lang.Object obj)
|
void |
flush()
NO-OP |
java.lang.Object |
get(java.io.Serializable key)
Checks the per-transaction caches for the object before going to the shared cache. |
java.util.Collection |
getKeys()
The keys returned are a union of the set of keys in the current transaction and those in the backing cache. |
int |
hashCode()
|
void |
put(java.io.Serializable key,
java.lang.Object value)
Goes direct to the shared cache in the absence of a transaction. |
void |
remove(java.io.Serializable key)
Goes direct to the shared cache in the absence of a transaction. |
void |
setMaxCacheSize(int maxCacheSize)
Set the maximum number of elements to store in the update and remove caches. |
void |
setName(java.lang.String name)
Set the name that identifies this cache from other instances. |
void |
setSharedCache(org.alfresco.repo.cache.SimpleCache sharedCache)
Set the shared cache to use during transaction synchronization or when no transaction is present. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public TransactionalCache()
| Method Detail |
|---|
public java.lang.String toString()
toString in class java.lang.ObjectTransactionalCache.setName(String)public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic void setSharedCache(org.alfresco.repo.cache.SimpleCache sharedCache)
sharedCache - public void setMaxCacheSize(int maxCacheSize)
The removed list will overflow to disk in order to ensure that deletions are not lost.
maxCacheSize - public void setName(java.lang.String name)
name -
public void afterPropertiesSet()
throws java.lang.Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjava.lang.Exceptionpublic boolean contains(java.io.Serializable key)
contains in interface org.alfresco.repo.cache.SimpleCachepublic java.util.Collection getKeys()
getKeys in interface org.alfresco.repo.cache.SimpleCachepublic java.lang.Object get(java.io.Serializable key)
get in interface org.alfresco.repo.cache.SimpleCache
public void put(java.io.Serializable key,
java.lang.Object value)
Where a transaction is present, a cache of updated items is lazily added to the thread and the Object put onto that.
put in interface org.alfresco.repo.cache.SimpleCachepublic void remove(java.io.Serializable key)
Where a transaction is present, a cache of removed items is lazily added to the thread and the Object put onto that.
remove in interface org.alfresco.repo.cache.SimpleCachepublic void clear()
clear in interface org.alfresco.repo.cache.SimpleCachepublic void flush()
flush in interface TransactionListenerpublic void beforeCompletion()
beforeCompletion in interface TransactionListenerpublic void beforeCommit(boolean readOnly)
beforeCommit in interface TransactionListenerreadOnly - true if the transaction is read-onlypublic void afterCommit()
afterCommit in interface TransactionListenerpublic void afterRollback()
afterRollback in interface TransactionListener
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||