Skip to content

Commit 4f6f2c0

Browse files
committed
Revert to separate get/put steps against method cache for concurrency
Closes gh-32958
1 parent e6da2a8 commit 4f6f2c0

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

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

+14-7
Original file line numberDiff line numberDiff line change
@@ -488,20 +488,27 @@ public int countAdvicesOfType(@Nullable Class<?> adviceClass) {
488488
* @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
489489
*/
490490
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class<?> targetClass) {
491-
if (this.methodCache == null) {
491+
List<Object> cachedInterceptors;
492+
if (this.methodCache != null) {
493+
// Method-specific cache for method-specific pointcuts
494+
MethodCacheKey cacheKey = new MethodCacheKey(method);
495+
cachedInterceptors = this.methodCache.get(cacheKey);
496+
if (cachedInterceptors == null) {
497+
cachedInterceptors = this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(
498+
this, method, targetClass);
499+
this.methodCache.put(cacheKey, cachedInterceptors);
500+
}
501+
}
502+
else {
492503
// Shared cache since there are no method-specific advisors (see below).
493-
List<Object> cachedInterceptors = this.cachedInterceptors;
504+
cachedInterceptors = this.cachedInterceptors;
494505
if (cachedInterceptors == null) {
495506
cachedInterceptors = this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(
496507
this, method, targetClass);
497508
this.cachedInterceptors = cachedInterceptors;
498509
}
499-
return cachedInterceptors;
500510
}
501-
502-
// Method-specific cache for method-specific pointcuts
503-
return this.methodCache.computeIfAbsent(new MethodCacheKey(method), k ->
504-
this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(this, method, targetClass));
511+
return cachedInterceptors;
505512
}
506513

507514
/**

0 commit comments

Comments
 (0)