Class TransactionAwareCacheManagerProxy
- java.lang.Object
- org.springframework.cache.transaction.TransactionAwareCacheManagerProxy
- All Implemented Interfaces:
InitializingBean
,CacheManager
public class TransactionAwareCacheManagerProxy extends Object implements CacheManager, InitializingBean
Proxy for a targetCacheManager
, exposing transaction-awareCache
objects which synchronize theirCache.put(java.lang.Object, java.lang.Object)
operations with Spring-managed transactions (through Spring'sTransactionSynchronizationManager
, performing the actual cache put operation only in the after-commit phase of a successful transaction. If no transaction is active,Cache.put(java.lang.Object, java.lang.Object)
operations will be performed immediately, as usual.- Since:
- 3.2
- Author:
- Juergen Hoeller
- See Also:
setTargetCacheManager(org.springframework.cache.CacheManager)
,TransactionAwareCacheDecorator
,TransactionSynchronizationManager
Constructor Summary
Constructors Constructor Description TransactionAwareCacheManagerProxy()
Create a new TransactionAwareCacheManagerProxy, setting the target CacheManager through thesetTargetCacheManager(org.springframework.cache.CacheManager)
bean property.TransactionAwareCacheManagerProxy(CacheManager targetCacheManager)
Create a new TransactionAwareCacheManagerProxy for the given target CacheManager.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.Cache
getCache(String name)
Get the cache associated with the given name.Collection<String>
getCacheNames()
Get a collection of the cache names known by this manager.void
setTargetCacheManager(CacheManager targetCacheManager)
Set the target CacheManager to proxy.
Constructor Detail
TransactionAwareCacheManagerProxy
public TransactionAwareCacheManagerProxy()
Create a new TransactionAwareCacheManagerProxy, setting the target CacheManager through thesetTargetCacheManager(org.springframework.cache.CacheManager)
bean property.
TransactionAwareCacheManagerProxy
public TransactionAwareCacheManagerProxy(CacheManager targetCacheManager)
Create a new TransactionAwareCacheManagerProxy for the given target CacheManager.- Parameters:
targetCacheManager
- the target CacheManager to proxy
Method Detail
setTargetCacheManager
public void setTargetCacheManager(CacheManager targetCacheManager)
Set the target CacheManager to proxy.
afterPropertiesSet
public void afterPropertiesSet()
Description copied from interface:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
getCache
@Nullable public Cache getCache(String name)
Description copied from interface:CacheManager
Get the cache associated with the given name.Note that the cache may be lazily created at runtime if the native provider supports it.
- Specified by:
getCache
in interfaceCacheManager
- Parameters:
name
- the cache identifier (must not benull
)- Returns:
- the associated cache, or
null
if such a cache does not exist or could be not created
getCacheNames
public Collection<String> getCacheNames()
Description copied from interface:CacheManager
Get a collection of the cache names known by this manager.- Specified by:
getCacheNames
in interfaceCacheManager
- Returns:
- the names of all caches known by the cache manager