Class SoftReferenceMapRetryContextCache

java.lang.Object
org.springframework.retry.policy.SoftReferenceMapRetryContextCache
All Implemented Interfaces:
RetryContextCache

public class SoftReferenceMapRetryContextCache extends Object implements RetryContextCache
Map-based implementation of RetryContextCache. The map backing the cache of contexts is synchronized and its entries are soft-referenced, so may be garbage collected under pressure.
Author:
Dave Syer
See Also:
  • Field Details

    • DEFAULT_CAPACITY

      public static final int DEFAULT_CAPACITY
      Default value for maximum capacity of the cache. This is set to a reasonably low value (4096) to avoid users inadvertently filling the cache with item keys that are inconsistent.
      See Also:
  • Constructor Details

    • SoftReferenceMapRetryContextCache

      public SoftReferenceMapRetryContextCache()
      Create a SoftReferenceMapRetryContextCache with default capacity.
    • SoftReferenceMapRetryContextCache

      public SoftReferenceMapRetryContextCache(int defaultCapacity)
      Parameters:
      defaultCapacity - the default capacity
  • Method Details

    • setCapacity

      public void setCapacity(int capacity)
      Public setter for the capacity. Prevents the cache from growing unboundedly if items that fail are misidentified and two references to an identical item actually do not have the same key. This can happen when users implement equals and hashCode based on mutable fields, for instance.
      Parameters:
      capacity - the capacity to set
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface RetryContextCache
    • get

      public RetryContext get(Object key)
      Specified by:
      get in interface RetryContextCache
    • put

      public void put(Object key, RetryContext context)
      Specified by:
      put in interface RetryContextCache
    • remove

      public void remove(Object key)
      Specified by:
      remove in interface RetryContextCache