public class TransactionalCacheFactory extends Object implements LockFactory, com.atlassian.cache.CacheFactory
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 and Description |
---|
TransactionalCacheFactory(com.atlassian.cache.CacheFactory cacheFactory,
LockFactory lockFactory,
SynchronizationManager synchronizationManager,
ConfluenceMonitoring confluenceMonitoring) |
Modifier and Type | Method and Description |
---|---|
void |
clearCurrentThreadTransactionalCaches()
Intended for use in testing.
|
<K,V> @NonNull com.atlassian.cache.Cache<K,V> |
getCache(@NonNull Class<?> owningClass,
@NonNull String name) |
<K,V> @NonNull com.atlassian.cache.Cache<K,V> |
getCache(@NonNull String name) |
<K,V> @NonNull com.atlassian.cache.Cache<K,V> |
getCache(@NonNull String name,
com.atlassian.cache.CacheLoader<K,V> loader) |
<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) |
<K,V> @NonNull com.atlassian.cache.Cache<K,V> |
getCache(@NonNull String name,
@NonNull Class<K> keyType,
@NonNull Class<V> valueType) |
<V> @NonNull com.atlassian.cache.CachedReference<V> |
getCachedReference(@NonNull Class<?> owningClass,
@NonNull String name,
@NonNull com.atlassian.cache.Supplier<V> supplier) |
<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) |
<V> @NonNull com.atlassian.cache.CachedReference<V> |
getCachedReference(@NonNull String name,
@NonNull com.atlassian.cache.Supplier<V> supplier) |
<V> @NonNull com.atlassian.cache.CachedReference<V> |
getCachedReference(@NonNull String name,
@NonNull com.atlassian.cache.Supplier<V> supplier,
@NonNull com.atlassian.cache.CacheSettings required) |
Lock |
getLock(String cacheName)
Get a lock -- getting the lock does *not* imply that it has been acquired.
|
public TransactionalCacheFactory(com.atlassian.cache.CacheFactory cacheFactory, LockFactory lockFactory, SynchronizationManager synchronizationManager, ConfluenceMonitoring confluenceMonitoring)
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)
getCache
in interface com.atlassian.cache.CacheFactory
public Lock getLock(String cacheName)
LockFactory
Lock.tryLock()
or Lock.lock()
on the returned object to
acquire the lock.getLock
in interface LockFactory
public void clearCurrentThreadTransactionalCaches()
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.
CacheManager.flushCaches()
public <K,V> @NonNull com.atlassian.cache.Cache<K,V> getCache(@NonNull String name, @NonNull Class<K> keyType, @NonNull Class<V> valueType)
getCache
in interface com.atlassian.cache.CacheFactory
public <K,V> @NonNull com.atlassian.cache.Cache<K,V> getCache(@NonNull Class<?> owningClass, @NonNull String name)
getCache
in interface com.atlassian.cache.CacheFactory
public <K,V> @NonNull com.atlassian.cache.Cache<K,V> getCache(@NonNull String name, com.atlassian.cache.CacheLoader<K,V> loader)
getCache
in interface com.atlassian.cache.CacheFactory
public <K,V> @NonNull com.atlassian.cache.Cache<K,V> getCache(@NonNull String name)
getCache
in interface com.atlassian.cache.CacheFactory
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)
getCachedReference
in interface com.atlassian.cache.CacheFactory
public <V> @NonNull com.atlassian.cache.CachedReference<V> getCachedReference(@NonNull String name, @NonNull com.atlassian.cache.Supplier<V> supplier)
getCachedReference
in interface com.atlassian.cache.CacheFactory
public <V> @NonNull com.atlassian.cache.CachedReference<V> getCachedReference(@NonNull Class<?> owningClass, @NonNull String name, @NonNull com.atlassian.cache.Supplier<V> supplier)
getCachedReference
in interface com.atlassian.cache.CacheFactory
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)
getCachedReference
in interface com.atlassian.cache.CacheFactory
Copyright © 2003–2019 Atlassian. All rights reserved.