|
|||||||||
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.
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)
Merge the transactional caches into the shared cache |
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 |
setDisableSharedCache(boolean disableSharedCache)
Set whether values must be written through to the shared cache or not |
void |
setMaxCacheSize(int maxCacheSize)
Set the maximum number of elements to store in the update and remove caches. |
void |
setMutable(boolean isMutable)
|
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.Object
TransactionalCache.setName(String)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public void setSharedCache(org.alfresco.repo.cache.SimpleCache sharedCache)
sharedCache
- underlying cache shared by transactionspublic void setDisableSharedCache(boolean disableSharedCache)
disableSharedCache
- true to prevent values from being written to
the shared cachepublic void setMutable(boolean isMutable)
isMutable
- true if the data stored in the cache is modifiablepublic 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.InitializingBean
java.lang.Exception
public boolean contains(java.io.Serializable key)
contains
in interface org.alfresco.repo.cache.SimpleCache
public java.util.Collection getKeys()
getKeys
in interface org.alfresco.repo.cache.SimpleCache
public 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.SimpleCache
public 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.SimpleCache
public void clear()
clear
in interface org.alfresco.repo.cache.SimpleCache
public void flush()
flush
in interface TransactionListener
public void beforeCompletion()
beforeCompletion
in interface TransactionListener
public void beforeCommit(boolean readOnly)
beforeCommit
in interface TransactionListener
readOnly
- true if the transaction is read-onlypublic void afterCommit()
afterCommit
in interface TransactionListener
public void afterRollback()
afterRollback
in interface TransactionListener
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |