Class TransactionAwareCacheDecorator
java.lang.Object
org.springframework.cache.transaction.TransactionAwareCacheDecorator
- All Implemented Interfaces:
org.springframework.cache.Cache
public class TransactionAwareCacheDecorator
extends Object
implements org.springframework.cache.Cache
Cache decorator which synchronizes its
put(java.lang.Object, java.lang.Object), evict(java.lang.Object) and
clear() operations with Spring-managed transactions (through Spring's
TransactionSynchronizationManager), performing the actual cache
put/evict/clear operation only in the after-commit phase of a successful
transaction. If no transaction is active, put(java.lang.Object, java.lang.Object), evict(java.lang.Object) and
clear() operations will be performed immediately, as usual.
Note: Use of immediate operations such as putIfAbsent(java.lang.Object, java.lang.Object) and
evictIfPresent(java.lang.Object) cannot be deferred to the after-commit phase of a
running transaction. Use these with care in a transactional environment.
- Since:
- 3.2
- Author:
- Juergen Hoeller, Stephane Nicoll, Stas Volsky
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.cache.Cache
org.springframework.cache.Cache.ValueRetrievalException, org.springframework.cache.Cache.ValueWrapper -
Constructor Summary
ConstructorsConstructorDescriptionTransactionAwareCacheDecorator(org.springframework.cache.Cache targetCache) Create a new TransactionAwareCache for the given target Cache. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()voidbooleanevictIfPresent(Object key) org.springframework.cache.Cache.ValueWrapper<T> T<T> TgetName()org.springframework.cache.CacheReturn the target Cache that this Cache should delegate to.booleanvoidorg.springframework.cache.Cache.ValueWrapperputIfAbsent(Object key, Object value) <T> CompletableFuture<T>retrieve(Object key, Supplier<CompletableFuture<T>> valueLoader)
-
Constructor Details
-
TransactionAwareCacheDecorator
public TransactionAwareCacheDecorator(org.springframework.cache.Cache targetCache) Create a new TransactionAwareCache for the given target Cache.- Parameters:
targetCache- the target Cache to decorate
-
-
Method Details
-
getTargetCache
public org.springframework.cache.Cache getTargetCache()Return the target Cache that this Cache should delegate to. -
getName
- Specified by:
getNamein interfaceorg.springframework.cache.Cache
-
getNativeCache
- Specified by:
getNativeCachein interfaceorg.springframework.cache.Cache
-
get
- Specified by:
getin interfaceorg.springframework.cache.Cache
-
get
- Specified by:
getin interfaceorg.springframework.cache.Cache
-
get
- Specified by:
getin interfaceorg.springframework.cache.Cache
-
retrieve
- Specified by:
retrievein interfaceorg.springframework.cache.Cache
-
retrieve
- Specified by:
retrievein interfaceorg.springframework.cache.Cache
-
put
- Specified by:
putin interfaceorg.springframework.cache.Cache
-
putIfAbsent
@Nullable public org.springframework.cache.Cache.ValueWrapper putIfAbsent(Object key, @Nullable Object value) - Specified by:
putIfAbsentin interfaceorg.springframework.cache.Cache
-
evict
- Specified by:
evictin interfaceorg.springframework.cache.Cache
-
evictIfPresent
- Specified by:
evictIfPresentin interfaceorg.springframework.cache.Cache
-
clear
public void clear()- Specified by:
clearin interfaceorg.springframework.cache.Cache
-
invalidate
public boolean invalidate()- Specified by:
invalidatein interfaceorg.springframework.cache.Cache
-