Skip to content

Cache Interceptor signature result #3396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/org/apache/ibatis/plugin/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.ibatis.reflection.ExceptionUtil;

Expand All @@ -30,6 +31,8 @@
*/
public class Plugin implements InvocationHandler {

private static final Map<Class<? extends Interceptor>, Map<Class<?>, Set<Method>>> signatureMapCache = new ConcurrentHashMap<>();

private final Object target;
private final Interceptor interceptor;
private final Map<Class<?>, Set<Method>> signatureMap;
Expand Down Expand Up @@ -64,6 +67,10 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
}

private static Map<Class<?>, Set<Method>> getSignatureMap(Interceptor interceptor) {
return signatureMapCache.computeIfAbsent(interceptor.getClass(), (clazz) -> createSignatureMap(interceptor));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest changing it to org.apache.ibatis.util.MapUtil#computeIfAbsent

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, it seemed that this method did not exist at the time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #3372

}

private static Map<Class<?>, Set<Method>> createSignatureMap(Interceptor interceptor) {
Intercepts interceptsAnnotation = interceptor.getClass().getAnnotation(Intercepts.class);
// issue #251
if (interceptsAnnotation == null) {
Expand Down