Always cache the context if it is global
Circuit breakers, for instance, would like to store some state for the duration of the lifetime of the circuit. So the normal rule that the cache is not used until there is an error doesn't make as much sense.
This commit is contained in:
@@ -402,14 +402,13 @@ public class RetryTemplate implements RetryOperations {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param retryPolicy the retry policy
|
||||
* @param state the retry state
|
||||
* @param context the retry context
|
||||
* @param e the exception thrown
|
||||
*/
|
||||
protected void registerThrowable(RetryPolicy retryPolicy, RetryState state,
|
||||
RetryContext context, Throwable e) {
|
||||
registerContext(context, state);
|
||||
retryPolicy.registerThrowable(context, e);
|
||||
}
|
||||
|
||||
private void registerContext(RetryContext context, RetryState state) {
|
||||
if (state != null) {
|
||||
Object key = state.getKey();
|
||||
if (context.getRetryCount() > 0 && !this.retryContextCache.containsKey(key)) {
|
||||
@@ -420,7 +419,6 @@ public class RetryTemplate implements RetryOperations {
|
||||
}
|
||||
this.retryContextCache.put(key, context);
|
||||
}
|
||||
retryPolicy.registerThrowable(context, e);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -473,6 +471,9 @@ public class RetryTemplate implements RetryOperations {
|
||||
if (state != null) {
|
||||
context.setAttribute(RetryContext.STATE_KEY, state.getKey());
|
||||
}
|
||||
if (context.hasAttribute(GLOBAL_STATE)) {
|
||||
registerContext(context, state);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user