java.lang.Object
org.springframework.retry.policy.AbstractMapRetryContextCache<V>
- All Implemented Interfaces:
RetryContextCache
- Direct Known Subclasses:
MapRetryContextCache,SoftReferenceMapRetryContextCache
Base
RetryContextCache implementation that stores entries in memory, with a
configurable maximum capacity and LRU eviction policy. For a cache used in a global
state, any attempt to increase its capacity should result in an exception. However, a
regular cache should not have permanent entries, and removing the eldest entries is
sensible.- Since:
- 1.3.5
- Author:
- Stephane Nicoll
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault value for maximum capacity of the cache. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractMapRetryContextCache(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 abstract RetryContextGet theRetryContextfrom the cache value.getMap()voidput(Object key, RetryContext context) voidprotected voidsetCapacity(int capacity) Update the capacity of the cache.protected abstract VtoValue(RetryContext context) Compute the value to store in the cache.
-
Field Details
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITYDefault 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
-
AbstractMapRetryContextCache
protected AbstractMapRetryContextCache(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
-
-
Method Details
-
getMap
-
setCapacity
protected void setCapacity(int capacity) Update the capacity of the cache.- Parameters:
capacity- the new capacity
-
containsKey
- Specified by:
containsKeyin interfaceRetryContextCache
-
get
- Specified by:
getin interfaceRetryContextCache
-
put
- Specified by:
putin interfaceRetryContextCache
-
remove
- Specified by:
removein interfaceRetryContextCache
-
toValue
Compute the value to store in the cache.- Parameters:
context- theRetryContextto store- Returns:
- the cache value
-
fromValue
Get theRetryContextfrom the cache value.- Parameters:
value- the cache value- Returns:
- the retry context
-