com.atlassian.confluence.cache
Class TransactionalCacheFactory

java.lang.Object
  extended by com.atlassian.confluence.cache.TransactionalCacheFactory
All Implemented Interfaces:
com.atlassian.cache.CacheFactory, ReadThroughCacheFactory, LockFactory

public class TransactionalCacheFactory
extends java.lang.Object
implements LockFactory, ReadThroughCacheFactory

A cache factory that produces transactional caches. These caches perform their updates only when the current transaction is successfully committed. Caches obtained outside of a transaction will pass updates immediately to the target cache while posting a warning to the cache factory log.

Transactional caches returned by this factory make a best effort at committing changes to the underlying cache, but they don't recover well from failure (caches with failures will be flushed), and there is no way that the associated database transaction can be rolled back if the cache updates fail.

Cache updates that are to be performed outside of a transaction that are not transactionally significant can be performed via a cache obtained from getReadThroughCacheForUpdate(String). One example of such a use would be cache read through.

Transaction synchronization is performed via the provided SynchronizationManager.

All updates to underlying caches are performed inside a lock on the cache to prevent other writes occurring at the same time. This applies for updates done post-commit for transaction-based caches, as well as those done via the read-through update method.


Constructor Summary
TransactionalCacheFactory(com.atlassian.cache.CacheFactory cacheFactory, LockFactory lockFactory, SynchronizationManager synchronizationManager)
           
 
Method Summary
<K,V> com.atlassian.cache.Cache<K,V>
getCache(java.lang.Class<?> owningClass, java.lang.String name)
           
<K,V> com.atlassian.cache.Cache<K,V>
getCache(java.lang.String cacheName)
           
<K,V> com.atlassian.cache.Cache<K,V>
getCache(java.lang.String name, com.atlassian.cache.CacheLoader<K,V> loader)
           
<K,V> com.atlassian.cache.Cache<K,V>
getCache(java.lang.String name, com.atlassian.cache.CacheLoader<K,V> loader, com.atlassian.cache.CacheSettings required)
           
<K,V> com.atlassian.cache.Cache<K,V>
getCache(java.lang.String name, java.lang.Class<K> keyType, java.lang.Class<V> valueType)
           
<V> com.atlassian.cache.CachedReference<V>
getCachedReference(java.lang.Class<?> owningClass, java.lang.String name, com.atlassian.cache.Supplier<V> supplier)
           
<V> com.atlassian.cache.CachedReference<V>
getCachedReference(java.lang.Class<?> owningClass, java.lang.String name, com.atlassian.cache.Supplier<V> supplier, com.atlassian.cache.CacheSettings required)
           
<V> com.atlassian.cache.CachedReference<V>
getCachedReference(java.lang.String name, com.atlassian.cache.Supplier<V> supplier)
           
<V> com.atlassian.cache.CachedReference<V>
getCachedReference(java.lang.String name, com.atlassian.cache.Supplier<V> supplier, com.atlassian.cache.CacheSettings required)
           
 Lock getLock(java.lang.String cacheName)
          Get a lock -- getting the lock does *not* imply that it has been acquired.
<K,V> com.atlassian.cache.Cache<K,V>
getReadThroughCacheForUpdate(java.lang.String cacheName)
          Returns the requested cache with no transactional wrapper for updates read from the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionalCacheFactory

public TransactionalCacheFactory(com.atlassian.cache.CacheFactory cacheFactory,
                                 LockFactory lockFactory,
                                 SynchronizationManager synchronizationManager)
Method Detail

getCache

public <K,V> com.atlassian.cache.Cache<K,V> getCache(java.lang.String cacheName)
Specified by:
getCache in interface com.atlassian.cache.CacheFactory

getReadThroughCacheForUpdate

public <K,V> com.atlassian.cache.Cache<K,V> getReadThroughCacheForUpdate(java.lang.String cacheName)
Returns the requested cache with no transactional wrapper for updates read from the database. Calls to Cache.put(Object, Object) are performed under the appropriate cache lock to prevent concurrent writes.

Specified by:
getReadThroughCacheForUpdate in interface ReadThroughCacheFactory

getLock

public Lock getLock(java.lang.String cacheName)
Description copied from interface: LockFactory
Get a lock -- getting the lock does *not* imply that it has been acquired. Call Lock.tryLock() or Lock.lock() on the returned object to acquire the lock.

Specified by:
getLock in interface LockFactory
Returns:
a lock in the transactional cache lock namespace.

getCache

public <K,V> com.atlassian.cache.Cache<K,V> getCache(java.lang.String name,
                                                     java.lang.Class<K> keyType,
                                                     java.lang.Class<V> valueType)
Specified by:
getCache in interface com.atlassian.cache.CacheFactory

getCache

public <K,V> com.atlassian.cache.Cache<K,V> getCache(java.lang.Class<?> owningClass,
                                                     java.lang.String name)
Specified by:
getCache in interface com.atlassian.cache.CacheFactory

getCache

public <K,V> com.atlassian.cache.Cache<K,V> getCache(java.lang.String name,
                                                     com.atlassian.cache.CacheLoader<K,V> loader)
Specified by:
getCache in interface com.atlassian.cache.CacheFactory

getCache

public <K,V> com.atlassian.cache.Cache<K,V> getCache(java.lang.String name,
                                                     com.atlassian.cache.CacheLoader<K,V> loader,
                                                     com.atlassian.cache.CacheSettings required)
Specified by:
getCache in interface com.atlassian.cache.CacheFactory

getCachedReference

public <V> com.atlassian.cache.CachedReference<V> getCachedReference(java.lang.String name,
                                                                     com.atlassian.cache.Supplier<V> supplier)
Specified by:
getCachedReference in interface com.atlassian.cache.CacheFactory

getCachedReference

public <V> com.atlassian.cache.CachedReference<V> getCachedReference(java.lang.String name,
                                                                     com.atlassian.cache.Supplier<V> supplier,
                                                                     com.atlassian.cache.CacheSettings required)
Specified by:
getCachedReference in interface com.atlassian.cache.CacheFactory

getCachedReference

public <V> com.atlassian.cache.CachedReference<V> getCachedReference(java.lang.Class<?> owningClass,
                                                                     java.lang.String name,
                                                                     com.atlassian.cache.Supplier<V> supplier)
Specified by:
getCachedReference in interface com.atlassian.cache.CacheFactory

getCachedReference

public <V> com.atlassian.cache.CachedReference<V> getCachedReference(java.lang.Class<?> owningClass,
                                                                     java.lang.String name,
                                                                     com.atlassian.cache.Supplier<V> supplier,
                                                                     com.atlassian.cache.CacheSettings required)
Specified by:
getCachedReference in interface com.atlassian.cache.CacheFactory


Copyright © 2003-2014 Atlassian. All Rights Reserved.