Browse Source

Revert to separate get/put steps against method cache for concurrency

Closes gh-32958
pull/33047/head
Juergen Hoeller 2 years ago
parent
commit
4f6f2c0d41
  1. 21
      spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java

21
spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java

@ -488,20 +488,27 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
* @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers) * @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
*/ */
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class<?> targetClass) { public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class<?> targetClass) {
if (this.methodCache == null) { List<Object> cachedInterceptors;
if (this.methodCache != null) {
// Method-specific cache for method-specific pointcuts
MethodCacheKey cacheKey = new MethodCacheKey(method);
cachedInterceptors = this.methodCache.get(cacheKey);
if (cachedInterceptors == null) {
cachedInterceptors = this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(
this, method, targetClass);
this.methodCache.put(cacheKey, cachedInterceptors);
}
}
else {
// Shared cache since there are no method-specific advisors (see below). // Shared cache since there are no method-specific advisors (see below).
List<Object> cachedInterceptors = this.cachedInterceptors; cachedInterceptors = this.cachedInterceptors;
if (cachedInterceptors == null) { if (cachedInterceptors == null) {
cachedInterceptors = this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice( cachedInterceptors = this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(
this, method, targetClass); this, method, targetClass);
this.cachedInterceptors = cachedInterceptors; this.cachedInterceptors = cachedInterceptors;
} }
return cachedInterceptors;
} }
return cachedInterceptors;
// Method-specific cache for method-specific pointcuts
return this.methodCache.computeIfAbsent(new MethodCacheKey(method), k ->
this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(this, method, targetClass));
} }
/** /**

Loading…
Cancel
Save