org.springframework.cache.transaction

## Class TransactionAwareCacheDecorator

- java.lang.Object
- - org.springframework.cache.transaction.TransactionAwareCacheDecorator

- All Implemented Interfaces:
    Cache

      public class TransactionAwareCacheDecorator
      extends Object
      implements Cache

  Cache decorator which synchronizes its `put(java.lang.Object, java.lang.Object)` and `evict(java.lang.Object)` operations with Spring-managed transactions (through Spring's `TransactionSynchronizationManager`, performing the actual cache put/evict operation only in the after-commit phase of a successful transaction. If no transaction is active, `put(java.lang.Object, java.lang.Object)` and `evict(java.lang.Object)` operations will be performed immediately, as usual.
  Since:
    3.2
  Author:
    Juergen Hoeller
  See Also:
    `TransactionAwareCacheManagerProxy`

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.springframework.cache.Cache

      `Cache.ValueWrapper`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TransactionAwareCacheDecorator(Cache targetCache)` Create a new TransactionAwareCache for the given target Cache.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Remove all mappings from the cache.
    `void` | `evict(Object key)` Evict the mapping for this key from this cache if it is present.
    `Cache.ValueWrapper` | `get(Object key)` Return the value to which this cache maps the specified key.
    `String` | `getName()` Return the cache name.
    `Object` | `getNativeCache()` Return the the underlying native cache provider.
    `void` | `put(Object key, Object value)` Associate the specified value with the specified key in this cache.

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

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

- - ### Constructor Detail

    - #### TransactionAwareCacheDecorator

          public TransactionAwareCacheDecorator(Cache targetCache)

      Create a new TransactionAwareCache for the given target Cache.
      Parameters:
        `targetCache` - the target Cache to decorate

  - ### Method Detail

    - #### getName

          public String getName()

      Description copied from interface: `Cache`
      Return the cache name.
      Specified by:
        `getName` in interface `Cache`

    - #### getNativeCache

          public Object getNativeCache()

      Description copied from interface: `Cache`
      Return the the underlying native cache provider.
      Specified by:
        `getNativeCache` in interface `Cache`

    - #### get

          public Cache.ValueWrapper get(Object key)

      Description copied from interface: `Cache`
      Return the value to which this cache maps the specified key.

      Returns `null` if the cache contains no mapping for this key; otherwise, the cached value (which may be `null` itself) will be returned in a `Cache.ValueWrapper`.

      Specified by:
        `get` in interface `Cache`
      Parameters:
        `key` - the key whose associated value is to be returned
      Returns:
        the value to which this cache maps the specified key, contained within a `Cache.ValueWrapper` which may also hold a cached `null` value. A straight `null` being returned means that the cache contains no mapping for this key.

    - #### put

          public void put(Object key,
                 Object value)

      Description copied from interface: `Cache`
      Associate the specified value with the specified key in this cache.

      If the cache previously contained a mapping for this key, the old value is replaced by the specified value.

      Specified by:
        `put` in interface `Cache`
      Parameters:
        `key` - the key with which the specified value is to be associated
        `value` - the value to be associated with the specified key

    - #### evict

          public void evict(Object key)

      Description copied from interface: `Cache`
      Evict the mapping for this key from this cache if it is present.
      Specified by:
        `evict` in interface `Cache`
      Parameters:
        `key` - the key whose mapping is to be removed from the cache

    - #### clear

          public void clear()

      Description copied from interface: `Cache`
      Remove all mappings from the cache.
      Specified by:
        `clear` in interface `Cache`