Class TransactionalCacheFactory

java.lang.Object
com.atlassian.confluence.cache.TransactionalCacheFactory
All Implemented Interfaces:
com.atlassian.cache.CacheFactory, TransactionAwareCacheFactory

public class TransactionalCacheFactory extends Object implements com.atlassian.cache.CacheFactory, TransactionAwareCacheFactory
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.

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 Details

  • Method Details

    • getCache

      @Deprecated public <K, V> @NonNull com.atlassian.cache.Cache<K,V> getCache(@NonNull String cacheName, com.atlassian.cache.CacheLoader<K,V> loader, @NonNull com.atlassian.cache.CacheSettings required)
      Deprecated.
      Specified by:
      getCache in interface com.atlassian.cache.CacheFactory
    • clearCurrentThreadTransactionalCaches

      public void clearCurrentThreadTransactionalCaches()
      Intended for use in testing. Discard all transaction-scoped caches and cached references for the current thread's transaction.

      Cached values will be cleared. Cached (deferred) writes will be dropped - not written to the underlying cache. The underlying non-transactional cache will not be cleared: see CacheManager.flushCaches() for that.

      See Also:
      • CacheManager.flushCaches()
    • getTxCache

      public <K, V> TransactionAwareCache<K,V> getTxCache(String cacheName, com.atlassian.cache.CacheLoader<K,V> loader)
      Specified by:
      getTxCache in interface TransactionAwareCacheFactory
    • getTxCache

      public <K, V> TransactionAwareCache<K,V> getTxCache(String cacheName)
      Specified by:
      getTxCache in interface TransactionAwareCacheFactory
    • getCache

      @Deprecated public <K, V> @NonNull com.atlassian.cache.Cache<K,V> getCache(@NonNull String name, @NonNull Class<K> keyType, @NonNull Class<V> valueType)
      Deprecated.
      since 7.5 Use getTxCache(String)
      Specified by:
      getCache in interface com.atlassian.cache.CacheFactory
    • getCache

      @Deprecated public <K, V> @NonNull com.atlassian.cache.Cache<K,V> getCache(@NonNull Class<?> owningClass, @NonNull String name)
      Deprecated.
      since 7.5 Use getTxCache(String)
      Specified by:
      getCache in interface com.atlassian.cache.CacheFactory
    • getCache

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

      @Deprecated public <K, V> @NonNull com.atlassian.cache.Cache<K,V> getCache(@NonNull String name)
      Deprecated.
      since 7.5 Use getTxCache(String)
      Specified by:
      getCache in interface com.atlassian.cache.CacheFactory
    • getCachedReference

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

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

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

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