org.springframework.cache.transaction

## 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 target `CacheManager`, exposing transaction-aware `Cache` objects which synchronize their `Cache.put(java.lang.Object, java.lang.Object)` operations with Spring-managed transactions (through Spring's `TransactionSynchronizationManager`, 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 and Description
    `TransactionAwareCacheManagerProxy()` Create a new TransactionAwareCacheManagerProxy, setting the target CacheManager through the `setTargetCacheManager(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 and Description
    --- | ---
    `void` | `afterPropertiesSet()` Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
    `Cache` | `getCache(String name)` Return the cache associated with the given name.
    `Collection<String>` | `getCacheNames()` Return a collection of the cache names known by this manager.
    `void` | `setTargetCacheManager(CacheManager targetCacheManager)` Set the target CacheManager to proxy.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TransactionAwareCacheManagerProxy

          public TransactionAwareCacheManagerProxy()

      Create a new TransactionAwareCacheManagerProxy, setting the target CacheManager through the `setTargetCacheManager(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 a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

      This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

      Specified by:
        `afterPropertiesSet` in interface `InitializingBean`

    - #### getCache

          public Cache getCache(String name)

      Description copied from interface: `CacheManager`
      Return the cache associated with the given name.
      Specified by:
        `getCache` in interface `CacheManager`
      Parameters:
        `name` - the cache identifier (must not be `null`)
      Returns:
        the associated cache, or `null` if none found

    - #### getCacheNames

          public Collection<String> getCacheNames()

      Description copied from interface: `CacheManager`
      Return a collection of the cache names known by this manager.
      Specified by:
        `getCacheNames` in interface `CacheManager`
      Returns:
        the names of all caches known by the cache manager