diff --git a/.gitignore b/.gitignore index b9784dc9b280..648f8ec05970 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,5 @@ Thumbs.db # rust ignore *.lock + +.factorypath diff --git a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/BodyParamUtils.java b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/BodyParamUtils.java index 4368e976ea04..cda68dc5c549 100644 --- a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/BodyParamUtils.java +++ b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/BodyParamUtils.java @@ -17,8 +17,13 @@ package org.apache.shenyu.plugin.api.utils; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -27,12 +32,10 @@ import org.apache.shenyu.common.utils.ReflectUtils; import org.springframework.util.LinkedMultiValueMap; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; /** * Common rpc parameter builder utils. @@ -41,6 +44,11 @@ public final class BodyParamUtils { private static final Pattern QUERY_PARAM_PATTERN = Pattern.compile("([^&=]+)(=?)([^&]+)?"); + // Caffeine cache with maximum size of 5000 + private static final Cache BASE_TYPE_CACHE = Caffeine.newBuilder() + .maximumSize(5000) + .build(); + private BodyParamUtils() { } @@ -127,6 +135,7 @@ private static boolean isNameMapping(final String parameterTypes) { return parameterTypes.startsWith("{") && parameterTypes.endsWith("}"); } + /** * isBaseType. * @@ -134,10 +143,12 @@ private static boolean isNameMapping(final String parameterTypes) { * @return whether the base type is. */ private static boolean isBaseType(final String paramType) { - try { - return ReflectUtils.isPrimitives(ClassUtils.getClass(paramType)); - } catch (ClassNotFoundException e) { - return false; - } + return BASE_TYPE_CACHE.get(paramType, key -> { + try { + return ReflectUtils.isPrimitives(ClassUtils.getClass(key)); + } catch (ClassNotFoundException e) { + return false; + } + }); } }