Module spring.retry
Package org.springframework.retry.policy
Class SoftReferenceMapRetryContextCache
java.lang.Object
org.springframework.retry.policy.AbstractMapRetryContextCache<SoftReference<RetryContext>>
org.springframework.retry.policy.SoftReferenceMapRetryContextCache
- All Implemented Interfaces:
RetryContextCache
public class SoftReferenceMapRetryContextCache
extends AbstractMapRetryContextCache<SoftReference<RetryContext>>
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 Summary
Fields inherited from class org.springframework.retry.policy.AbstractMapRetryContextCache
DEFAULT_CAPACITY -
Constructor Summary
ConstructorsConstructorDescriptionCreate an instance withthe default capacitySoftReferenceMapRetryContextCache(int capacity) Create an instance with the given capacity, removing the eldest entries when the cache is fullSoftReferenceMapRetryContextCache(int capacity, boolean removeEldestEntries) Create an instance with the given capacity and the policy to apply when the cache is full. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(Object key) protected RetryContextfromValue(SoftReference<RetryContext> value) Get theRetryContextfrom the cache value.voidsetCapacity(int capacity) Update the capacity of this cache.protected SoftReference<RetryContext>toValue(RetryContext context) Compute the value to store in the cache.Methods inherited from class org.springframework.retry.policy.AbstractMapRetryContextCache
get, getMap, put, remove
-
Constructor Details
-
SoftReferenceMapRetryContextCache
public SoftReferenceMapRetryContextCache()Create an instance withthe default capacity -
SoftReferenceMapRetryContextCache
public SoftReferenceMapRetryContextCache(int capacity) Create an instance with the given capacity, removing the eldest entries when the cache is full- Parameters:
capacity- the initial capacity of the cache
-
SoftReferenceMapRetryContextCache
public SoftReferenceMapRetryContextCache(int capacity, boolean removeEldestEntries) Create an instance with the given capacity and the policy to apply when the cache is full.- Parameters:
capacity- the size of the cacheremoveEldestEntries- whether to remove the eldest entries when the cache is full- Since:
- 1.3.5
-
-
Method Details
-
setCapacity
public void setCapacity(int capacity) Update the capacity of this cache. Prevent 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.- Overrides:
setCapacityin classAbstractMapRetryContextCache<SoftReference<RetryContext>>- Parameters:
capacity- the capacity to set
-
containsKey
- Specified by:
containsKeyin interfaceRetryContextCache- Overrides:
containsKeyin classAbstractMapRetryContextCache<SoftReference<RetryContext>>
-
toValue
Description copied from class:AbstractMapRetryContextCacheCompute the value to store in the cache.- Specified by:
toValuein classAbstractMapRetryContextCache<SoftReference<RetryContext>>- Parameters:
context- theRetryContextto store- Returns:
- the cache value
-
fromValue
Description copied from class:AbstractMapRetryContextCacheGet theRetryContextfrom the cache value.- Specified by:
fromValuein classAbstractMapRetryContextCache<SoftReference<RetryContext>>- Parameters:
value- the cache value- Returns:
- the retry context
-