org.springframework.util

## Class CachingMapDecorator<K,V>

- java.lang.Object
- - org.springframework.util.CachingMapDecorator<K,V>

- All Implemented Interfaces:
    Serializable, Map<K,V>

  Deprecated.
  as of Spring 3.2, to be removed along with LabeledEnum support

      @Deprecated
      public abstract class CachingMapDecorator<K,V>
      extends Object
      implements Map<K,V>, Serializable

  A simple decorator for a Map, encapsulating the workflow for caching expensive values in a target Map. Supports caching weak or strong keys.

  This class is an abstract template. Caching Map implementations should subclass and override the `create(key)` method which encapsulates expensive creation of a new object.

  Since:
    1.2.2
  Author:
    Keith Donald, Juergen Hoeller
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface java.util.Map

      `Map.Entry<K,V>`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CachingMapDecorator()` Deprecated. Create a CachingMapDecorator with strong keys, using an underlying synchronized Map.
    `CachingMapDecorator(boolean weak)` Deprecated. Create a CachingMapDecorator, using an underlying synchronized Map.
    `CachingMapDecorator(boolean weak, int size)` Deprecated. Create a CachingMapDecorator with initial size, using an underlying synchronized Map.
    `CachingMapDecorator(Map<K,V> targetMap)` Deprecated. Create a CachingMapDecorator for the given Map.
    `CachingMapDecorator(Map<K,V> targetMap, boolean synchronize, boolean weak)` Deprecated. Create a CachingMapDecorator for the given Map.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Deprecated.
    `boolean` | `containsKey(Object key)` Deprecated.
    `boolean` | `containsValue(Object value)` Deprecated.
    `protected abstract V` | `create(K key)` Deprecated. Create a value to cache for the given key.
    `Set<Map.Entry<K,V>>` | `entrySet()` Deprecated.
    `V` | `get(Object key)` Deprecated. Get value for key.
    `boolean` | `isEmpty()` Deprecated.
    `Set<K>` | `keySet()` Deprecated.
    `V` | `put(K key, V value)` Deprecated. Put an object into the cache, possibly wrapping it with a weak reference.
    `void` | `putAll(Map<? extends K,? extends V> map)` Deprecated.
    `V` | `remove(Object key)` Deprecated.
    `int` | `size()` Deprecated.
    `String` | `toString()` Deprecated.
    `protected boolean` | `useWeakValue(K key, V value)` Deprecated. Decide whether to use a weak reference for the value of the given key-value pair.
    `Collection<V>` | `values()` Deprecated.

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

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

    - ### Methods inherited from interface java.util.Map

      `equals, hashCode`

- - ### Constructor Detail

    - #### CachingMapDecorator

          public CachingMapDecorator()

      Deprecated.
      Create a CachingMapDecorator with strong keys, using an underlying synchronized Map.

    - #### CachingMapDecorator

          public CachingMapDecorator(boolean weak)

      Deprecated.
      Create a CachingMapDecorator, using an underlying synchronized Map.
      Parameters:
        `weak` - whether to use weak references for keys and values

    - #### CachingMapDecorator

          public CachingMapDecorator(boolean weak,
                             int size)

      Deprecated.
      Create a CachingMapDecorator with initial size, using an underlying synchronized Map.
      Parameters:
        `weak` - whether to use weak references for keys and values
        `size` - the initial cache size

    - #### CachingMapDecorator

          public CachingMapDecorator(Map<K,V> targetMap)

      Deprecated.
      Create a CachingMapDecorator for the given Map.

      The passed-in Map won't get synchronized explicitly, so make sure to pass in a properly synchronized Map, if desired.

      Parameters:
        `targetMap` - the Map to decorate

    - #### CachingMapDecorator

          public CachingMapDecorator(Map<K,V> targetMap,
                             boolean synchronize,
                             boolean weak)

      Deprecated.
      Create a CachingMapDecorator for the given Map.

      The passed-in Map won't get synchronized explicitly unless you specify "synchronize" as "true".

      Parameters:
        `targetMap` - the Map to decorate
        `synchronize` - whether to synchronize on the given Map
        `weak` - whether to use weak references for values

  - ### Method Detail

    - #### size

          public int size()

      Deprecated.
      Specified by:
        `size` in interface `Map<K,V>`

    - #### isEmpty

          public boolean isEmpty()

      Deprecated.
      Specified by:
        `isEmpty` in interface `Map<K,V>`

    - #### containsKey

          public boolean containsKey(Object key)

      Deprecated.
      Specified by:
        `containsKey` in interface `Map<K,V>`

    - #### containsValue

          public boolean containsValue(Object value)

      Deprecated.
      Specified by:
        `containsValue` in interface `Map<K,V>`

    - #### remove

          public V remove(Object key)

      Deprecated.
      Specified by:
        `remove` in interface `Map<K,V>`

    - #### putAll

          public void putAll(Map<? extends K,? extends V> map)

      Deprecated.
      Specified by:
        `putAll` in interface `Map<K,V>`

    - #### clear

          public void clear()

      Deprecated.
      Specified by:
        `clear` in interface `Map<K,V>`

    - #### keySet

          public Set<K> keySet()

      Deprecated.
      Specified by:
        `keySet` in interface `Map<K,V>`

    - #### values

          public Collection<V> values()

      Deprecated.
      Specified by:
        `values` in interface `Map<K,V>`

    - #### entrySet

          public Set<Map.Entry<K,V>> entrySet()

      Deprecated.
      Specified by:
        `entrySet` in interface `Map<K,V>`

    - #### put

          public V put(K key,
              V value)

      Deprecated.
      Put an object into the cache, possibly wrapping it with a weak reference.
      Specified by:
        `put` in interface `Map<K,V>`
      See Also:
        `useWeakValue(Object, Object)`

    - #### useWeakValue

          protected boolean useWeakValue(K key,
                             V value)

      Deprecated.
      Decide whether to use a weak reference for the value of the given key-value pair.
      Parameters:
        `key` - the candidate key
        `value` - the candidate value
      Returns:
        `true` in order to use a weak reference; `false` otherwise.

    - #### get

          public V get(Object key)

      Deprecated.
      Get value for key. Creates and caches value if it doesn't already exist in the cache.

      This implementation is not synchronized: This is highly concurrent but does not guarantee unique instances in the cache, as multiple values for the same key could get created in parallel. Consider overriding this method to synchronize it, if desired.

      Specified by:
        `get` in interface `Map<K,V>`
      See Also:
        `create(Object)`

    - #### create

          protected abstract V create(K key)

      Deprecated.
      Create a value to cache for the given key. Called by `get` if there is no value cached already.
      Parameters:
        `key` - the cache key
      See Also:
        `get(Object)`

    - #### toString

          public String toString()

      Deprecated.
      Overrides:
        `toString` in class `Object`