This is an automated email from the ASF dual-hosted git repository.

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 1286b4a61 [type:fix] fix error cache usage (#4503)
1286b4a61 is described below

commit 1286b4a616c491bb617247bae1f4da3cad93e530
Author: moremind <[email protected]>
AuthorDate: Mon Mar 27 10:47:30 2023 +0800

    [type:fix] fix error cache usage (#4503)
    
    * [type:fix] fix error cache usage
    
    * [type:fix] fix error cache usage
    
    * [type:fix] fix error cache usage
    
    * [type:fix] fix error cache usage
    
    * [type:fix] fix error cache usage
    
    * [type:fix] fix error cache usage
---
 .../shenyu/common/cache/WindowTinyLFUMap.java      | 53 +++++++++++++++----
 .../shenyu/common/cache/WindowTinyLFUMapTest.java  | 52 +++++++++++++++++++
 .../shenyu/plugin/base/AbstractShenyuPlugin.java   | 11 +++-
 .../shenyu/plugin/base/cache/MatchDataCache.java   |  4 +-
 .../apache/shenyu/plugin/base/trie/ShenyuTrie.java | 59 +++++++++++++++-------
 .../shenyu/plugin/base/trie/ShenyuTrieNode.java    | 55 ++++++++++++++------
 .../plugin/base/cache/MatchDataCacheTest.java      |  4 +-
 7 files changed, 189 insertions(+), 49 deletions(-)

diff --git 
a/shenyu-common/src/main/java/org/apache/shenyu/common/cache/WindowTinyLFUMap.java
 
b/shenyu-common/src/main/java/org/apache/shenyu/common/cache/WindowTinyLFUMap.java
index cafe5a7af..826b645e4 100644
--- 
a/shenyu-common/src/main/java/org/apache/shenyu/common/cache/WindowTinyLFUMap.java
+++ 
b/shenyu-common/src/main/java/org/apache/shenyu/common/cache/WindowTinyLFUMap.java
@@ -22,17 +22,16 @@ import com.github.benmanes.caffeine.cache.Caffeine;
 
 import javax.annotation.concurrent.ThreadSafe;
 import java.io.Serializable;
-import java.lang.ref.WeakReference;
 import java.util.AbstractMap;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 /**
- * this cache is provided by caffeine, the cache has two implements including 
weak-key cache and regular cache.<br>
- * the weak-key cache applies to scenarios where objects can be collected. 
when memory lock causes full gc, the weakKey will collect by gc.<br>
- * the regular cache applies to immutable cache object data, and the user 
determines the cache size.<br>
- * about the weak-key cache and regular cache, please refer to:
- * <a href="https://github.com/ben-manes/caffeine/issues/776";>caffeine cache 
ISSUES #776</a>
+ * this cache is provided by caffeine, the cache has two implements including 
weak-key cache and strong-key cache.<br>
+ * <p>the weak-key cache applies to scenarios where objects can be collected. 
when memory lock causes full gc, the weakKey will collect by gc.</p>
+ * <p>the strong-key cache applies to immutable cache object data, and the 
user determines the cache size.</p>
+ * <p>about the weak-key cache and strong-key cache, please refer to:
+ * <a href="https://github.com/ben-manes/caffeine/issues/776";>caffeine cache 
ISSUES #776</a></p>
  */
 @ThreadSafe
 public class WindowTinyLFUMap<K, V> extends AbstractMap<K, V> implements 
Serializable {
@@ -42,9 +41,34 @@ public class WindowTinyLFUMap<K, V> extends AbstractMap<K, 
V> implements Seriali
     private final Cache<K, V> cache;
     
     /**
-     * initial caffeine cache.
-     * when weakKey is true, create weakKeys cache, please refer to: 
{@linkplain WeakReference},
-     * weak reference make cache be memory-safe. however, the weakKey is 
false, caffeine eject cache by strategy.
+     * build caffeine cache.
+     *
+     * @param maximumSize maximumSize
+     */
+    public WindowTinyLFUMap(final long maximumSize) {
+        this.cache = Caffeine.newBuilder()
+                .maximumSize(maximumSize)
+                .build();
+    }
+    
+    /**
+     * initial caffeine cache include WeakReference cache and StrongReference 
cache.
+     *
+     * <p>when the weakKey is true that means using weakKeys cache, gc will 
collect the weak key, please refer to:
+     * com.github.benmanes.caffeine.cache.References.WeakKeyReference</p>
+     *
+     * <p>when the weakKey is false, use strong reference, jvm maybe throw 
oom-error.</p>
+     *
+     * <pre>{@code Map<String, Object> strongMap = new WindowTinyLFUMap<>(100, 
100, Boolean.FALSE);
+     * strongMap.put(new String("abc"), 1);
+     * strongMap.put(new String("abc"), 1);
+     * assert strongMap.get("abc") != null;
+     *
+     * Map<String, Object> strongMap = new WindowTinyLFUMap<>(100, 100, 
Boolean.TRUE);
+     * strongMap.put(new String("abc"), 1);
+     * strongMap.put(new String("abc"), 1);
+     * assert strongMap.get("abc") == null;
+     * }</pre>
      *
      * @param initialCapacity initial capacity
      * @param maximumSize maximum size
@@ -103,6 +127,17 @@ public class WindowTinyLFUMap<K, V> extends AbstractMap<K, 
V> implements Seriali
         return value;
     }
     
+    @Override
+    public void clear() {
+        this.cache.invalidateAll();
+        this.cache.cleanUp();
+    }
+    
+    @Override
+    public int size() {
+        return this.cache.asMap().entrySet().size();
+    }
+    
     @Override
     public Set<Entry<K, V>> entrySet() {
         return cache.asMap().entrySet();
diff --git 
a/shenyu-common/src/test/java/org/apache/shenyu/common/cache/WindowTinyLFUMapTest.java
 
b/shenyu-common/src/test/java/org/apache/shenyu/common/cache/WindowTinyLFUMapTest.java
new file mode 100644
index 000000000..a2ae1450f
--- /dev/null
+++ 
b/shenyu-common/src/test/java/org/apache/shenyu/common/cache/WindowTinyLFUMapTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.common.cache;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+
+/**
+ * WindowTinyLFUMapTest.
+ */
+public class WindowTinyLFUMapTest {
+    
+    @Test
+    public void weakKeyCache() {
+        Map<String, String> map = new WindowTinyLFUMap<>(100, 100, 
Boolean.TRUE);
+        String key1 = new String("abc");
+        String key2 = new String("abc");
+        map.put(key1, "1");
+        map.put(key2, "1");
+        Assert.assertEquals(2, map.size());
+        Assert.assertEquals(key1, key2);
+        Assert.assertNull(map.get("abc"));
+    }
+    
+    @Test
+    public void strongKeyCache() {
+        Map<String, String> map = new WindowTinyLFUMap<>(100, 100, 
Boolean.FALSE);
+        String key1 = new String("abc");
+        String key2 = new String("abc");
+        map.put(key1, "1");
+        map.put(key2, "1");
+        Assert.assertEquals(map.get(key1), map.get(key2));
+        Assert.assertEquals(1, map.size());
+    }
+}
diff --git 
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/AbstractShenyuPlugin.java
 
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/AbstractShenyuPlugin.java
index c3bac8466..29ff186dc 100644
--- 
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/AbstractShenyuPlugin.java
+++ 
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/AbstractShenyuPlugin.java
@@ -142,6 +142,7 @@ public abstract class AbstractShenyuPlugin implements 
ShenyuPlugin {
                 ruleData = trieMatchRule(exchange, selectorData, path);
                 // trie cache fails to hit, execute default strategy
                 if (Objects.isNull(ruleData)) {
+                    LOG.info("{} rule match path from default strategy", 
named());
                     Pair<Boolean, RuleData> matchRuleData = 
matchRule(exchange, rules);
                     ruleData = matchRuleData.getRight();
                     if (matchRuleData.getLeft()) {
@@ -312,9 +313,15 @@ public abstract class AbstractShenyuPlugin implements 
ShenyuPlugin {
         RuleData ruleData = null;
         ShenyuTrieNode shenyuTrieNode = trie.match(path, selectorData.getId());
         if (Objects.nonNull(shenyuTrieNode)) {
-            List<RuleData> ruleDataList = 
shenyuTrieNode.getPathRuleCache().getIfPresent(selectorData.getId());
+            LOG.info("{} rule match path from shenyu trie", named());
+            List<RuleData> ruleDataList = 
shenyuTrieNode.getPathRuleCache().get(selectorData.getId());
             if (CollectionUtils.isNotEmpty(ruleDataList)) {
-                Pair<Boolean, RuleData> ruleDataPair = matchRule(exchange, 
ruleDataList);
+                Pair<Boolean, RuleData> ruleDataPair;
+                if (ruleDataList.size() > 1) {
+                    ruleDataPair = matchRule(exchange, ruleDataList);
+                } else {
+                    ruleDataPair = Pair.of(Boolean.TRUE, 
ruleDataList.stream().findFirst().orElse(null));
+                }
                 ruleData = ruleDataPair.getRight();
                 if (ruleDataPair.getLeft()) {
                     // exist only one rule data, cache rule
diff --git 
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MatchDataCache.java
 
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MatchDataCache.java
index 0294474fa..4665140f1 100644
--- 
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MatchDataCache.java
+++ 
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MatchDataCache.java
@@ -84,7 +84,7 @@ public final class MatchDataCache {
      */
     public void cacheSelectorData(final String path, final SelectorData 
selectorData, final int initialCapacity, final long maximumSize) {
         MapUtils.computeIfAbsent(SELECTOR_DATA_MAP, 
selectorData.getPluginName(), map ->
-                new WindowTinyLFUMap<>(initialCapacity, maximumSize, 
Boolean.TRUE)).put(path, selectorData);
+                new WindowTinyLFUMap<>(initialCapacity, maximumSize, 
Boolean.FALSE)).put(path, selectorData);
     }
 
     /**
@@ -109,7 +109,7 @@ public final class MatchDataCache {
      */
     public void cacheRuleData(final String path, final RuleData ruleData, 
final int initialCapacity, final long maximumSize) {
         MapUtils.computeIfAbsent(RULE_DATA_MAP, ruleData.getPluginName(), map 
->
-                new WindowTinyLFUMap<>(initialCapacity, maximumSize, 
Boolean.TRUE)).put(path, ruleData);
+                new WindowTinyLFUMap<>(initialCapacity, maximumSize, 
Boolean.FALSE)).put(path, ruleData);
     }
     
     /**
diff --git 
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
 
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
index 6129aa231..9e0093403 100644
--- 
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
+++ 
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
@@ -17,18 +17,20 @@
 
 package org.apache.shenyu.plugin.base.trie;
 
-import com.github.benmanes.caffeine.cache.Cache;
-import com.github.benmanes.caffeine.cache.Caffeine;
 import com.google.common.collect.Lists;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.shenyu.common.cache.WindowTinyLFUMap;
 import org.apache.shenyu.common.dto.RuleData;
 import org.apache.shenyu.common.enums.TrieMatchModeEvent;
 
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 public class ShenyuTrie {
 
@@ -74,8 +76,8 @@ public class ShenyuTrie {
      * @return status
      */
     public boolean isEmpty() {
-        return this.root.getChildren().estimatedSize() == 0
-                && this.root.getPathVariablesSet().estimatedSize() == 0
+        return this.root.getChildren().size() == 0
+                && this.root.getPathVariablesSet().size() == 0
                 && Objects.isNull(this.root.getPathVariableNode());
     }
 
@@ -112,9 +114,10 @@ public class ShenyuTrie {
                 // after insert node, set full path and end of path
                 node.setFullPath(uriPath);
                 node.setEndOfPath(true);
+                node.setSelectorId(ruleData.getSelectorId());
                 node.setBizInfo(bizInfo);
                 if (Objects.isNull(node.getPathRuleCache())) {
-                    
node.setPathRuleCache(Caffeine.newBuilder().maximumSize(pathRuleCacheSize).build());
+                    node.setPathRuleCache(new 
WindowTinyLFUMap<>(pathRuleCacheSize));
                 }
                 List<RuleData> ruleDataList = getVal(node.getPathRuleCache(), 
ruleData.getSelectorId());
                 if (CollectionUtils.isNotEmpty(ruleDataList)) {
@@ -175,7 +178,7 @@ public class ShenyuTrie {
                 childNode.setMatchStr(segment);
                 childNode.setEndOfPath(false);
                 if (Objects.isNull(shenyuTrieNode.getPathVariablesSet())) {
-                    
shenyuTrieNode.setPathVariablesSet(Caffeine.newBuilder().maximumSize(pathVariableSize).build());
+                    shenyuTrieNode.setPathVariablesSet(new 
WindowTinyLFUMap<>(pathVariableSize));
                 }
                 shenyuTrieNode.getPathVariablesSet().put(segment, childNode);
                 shenyuTrieNode.setPathVariableNode(childNode);
@@ -195,7 +198,7 @@ public class ShenyuTrie {
      */
     private ShenyuTrieNode put(final String segment, final ShenyuTrieNode 
shenyuTrieNode, final boolean endOfPath) {
         if (Objects.isNull(shenyuTrieNode.getChildren())) {
-            
shenyuTrieNode.setChildren(Caffeine.newBuilder().maximumSize(childrenSize).build());
+            shenyuTrieNode.setChildren(new WindowTinyLFUMap<>(childrenSize));
         }
         ShenyuTrieNode childrenNode;
         if (containsKey(shenyuTrieNode.getChildren(), segment)) {
@@ -225,7 +228,7 @@ public class ShenyuTrie {
                 ShenyuTrieNode currentNode = root;
                 for (int i = 0; i < pathParts.length; i++) {
                     String path = pathParts[i];
-                    currentNode = matchNode(path, currentNode);
+                    currentNode = matchNode(path, currentNode, selectorId);
                     if (Objects.nonNull(currentNode)) {
                         boolean endPath = judgeEqual(i, pathParts.length - 1);
                         // path is not end, continue to execute
@@ -233,7 +236,12 @@ public class ShenyuTrie {
                             continue;
                         }
                         // include path variable node, general node, wildcard 
node
-                        if ((endPath || (isMatchAll(currentNode.getMatchStr()) 
&& currentNode.getEndOfPath()))
+                        if (endPath && checkPathRuleNotNull(currentNode)
+                                && 
CollectionUtils.isNotEmpty(getVal(currentNode.getPathRuleCache(), selectorId))) 
{
+                            return currentNode;
+                        }
+                        // path is end and the match str is **, means match all
+                        if (isMatchAll(currentNode.getMatchStr()) && 
currentNode.getEndOfPath()
                                 && checkPathRuleNotNull(currentNode)
                                 && 
CollectionUtils.isNotEmpty(getVal(currentNode.getPathRuleCache(), selectorId))) 
{
                             return currentNode;
@@ -253,12 +261,17 @@ public class ShenyuTrie {
      *
      * @param segment path segment
      * @param node node
+     * @param selectorId selectorId
      * @return {@linkplain ShenyuTrieNode}
      */
-    private ShenyuTrieNode matchNode(final String segment, final 
ShenyuTrieNode node) {
+    private ShenyuTrieNode matchNode(final String segment, final 
ShenyuTrieNode node, final String selectorId) {
         if (Objects.nonNull(node)) {
             // node exist in children,first find path, avoid A plug have 
/http/**, B plug have /http/order/**
             if (checkChildrenNotNull(node)) {
+                Pair<Boolean, ShenyuTrieNode> pair = filterTrieNode(node, 
selectorId);
+                if (pair.getLeft()) {
+                    return pair.getRight();
+                }
                 if (containsKey(node.getChildren(), segment)) {
                     return getVal(node.getChildren(), segment);
                 }
@@ -318,8 +331,7 @@ public class ShenyuTrie {
                     String[] parentPathArray = Arrays.copyOfRange(pathParts, 
0, pathParts.length - 1);
                     String parentPath = String.join("/", parentPathArray);
                     ShenyuTrieNode parentNode = this.getNode(parentPath);
-                    parentNode.getChildren().invalidate(key);
-                    parentNode.getChildren().cleanUp();
+                    parentNode.getChildren().remove(key);
                 } else {
                     // remove plugin mapping
                     List<RuleData> delRuleData = 
getVal(currentNode.getPathRuleCache(), ruleData.getSelectorId());
@@ -350,6 +362,18 @@ public class ShenyuTrie {
         }
         return null;
     }
+    
+    private Pair<Boolean, ShenyuTrieNode> filterTrieNode(final ShenyuTrieNode 
node, final String selectorId) {
+        Map<String, ShenyuTrieNode> currentMap = node.getChildren();
+        List<ShenyuTrieNode> filterTrieNodes = currentMap.values().stream()
+                .filter(currentNode -> currentNode.getEndOfPath() && 
selectorId.equals(currentNode.getSelectorId()))
+                .collect(Collectors.toList());
+        if (filterTrieNodes.size() != 1) {
+            return Pair.of(Boolean.FALSE, null);
+        } else {
+            return Pair.of(Boolean.TRUE, 
filterTrieNodes.stream().findFirst().orElse(null));
+        }
+    }
 
     /**
      * get node.
@@ -442,22 +466,21 @@ public class ShenyuTrie {
         return Objects.nonNull(key) && key.startsWith("{") && 
key.endsWith("}");
     }
 
-    private static <V> boolean containsKey(final Cache<String, V> cache, final 
String key) {
+    private static <V> boolean containsKey(final Map<String, V> cache, final 
String key) {
         V ret = getVal(cache, key);
         return Objects.nonNull(ret);
     }
 
-    private static <V> V getVal(final Cache<String, V> cache, final String 
key) {
+    private static <V> V getVal(final Map<String, V> cache, final String key) {
         if (Objects.nonNull(cache)) {
-            return cache.getIfPresent(key);
+            return cache.get(key);
         }
         return null;
     }
     
-    private static <V> void cleanup(final Cache<String, V> cache) {
+    private static <V> void cleanup(final Map<String, V> cache) {
         if (Objects.nonNull(cache)) {
-            cache.invalidateAll();
-            cache.cleanUp();
+            cache.clear();
         }
     }
 
diff --git 
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieNode.java
 
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieNode.java
index fcec43d97..941811bec 100644
--- 
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieNode.java
+++ 
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrieNode.java
@@ -17,12 +17,12 @@
 
 package org.apache.shenyu.plugin.base.trie;
 
-import com.github.benmanes.caffeine.cache.Cache;
-import com.github.benmanes.caffeine.cache.Caffeine;
+import org.apache.shenyu.common.cache.WindowTinyLFUMap;
 import org.apache.shenyu.common.dto.RuleData;
 
 import java.io.Serializable;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 
 /**
@@ -45,12 +45,12 @@ public class ShenyuTrieNode implements Serializable {
     /**
      * in path /a/b/c, b is child of a, c is child of b.
      */
-    private Cache<String, ShenyuTrieNode> children;
+    private Map<String, ShenyuTrieNode> children;
 
     /**
      * path variables.
      */
-    private Cache<String, ShenyuTrieNode> pathVariablesSet;
+    private Map<String, ShenyuTrieNode> pathVariablesSet;
 
     /**
      * path variable node.
@@ -70,7 +70,9 @@ public class ShenyuTrieNode implements Serializable {
     /**
      * selectorId mapping to RuleData.
      */
-    private Cache<String, List<RuleData>> pathRuleCache;
+    private Map<String, List<RuleData>> pathRuleCache;
+    
+    private String selectorId;
 
     /**
      * biz info, route info and any other info store here, e.g. ruleId, 
selectorId and so on.
@@ -85,9 +87,9 @@ public class ShenyuTrieNode implements Serializable {
         this.matchStr = matchStr;
         this.fullPath = fullPath;
         this.endOfPath = endOfPath;
-        this.children = 
Caffeine.newBuilder().maximumSize(childrenSize).build();
-        this.pathRuleCache = 
Caffeine.newBuilder().maximumSize(pathRuleCacheSize).build();
-        this.pathVariablesSet = 
Caffeine.newBuilder().maximumSize(pathVariableSize).build();
+        this.children = new WindowTinyLFUMap<>(childrenSize);
+        this.pathRuleCache = new WindowTinyLFUMap<>(pathRuleCacheSize);
+        this.pathVariablesSet = new WindowTinyLFUMap<>(pathVariableSize);
     }
 
     /**
@@ -131,7 +133,7 @@ public class ShenyuTrieNode implements Serializable {
      *
      * @return trie children cache
      */
-    public Cache<String, ShenyuTrieNode> getChildren() {
+    public Map<String, ShenyuTrieNode> getChildren() {
         return children;
     }
 
@@ -140,7 +142,7 @@ public class ShenyuTrieNode implements Serializable {
      *
      * @return path variable
      */
-    public Cache<String, ShenyuTrieNode> getPathVariablesSet() {
+    public Map<String, ShenyuTrieNode> getPathVariablesSet() {
         return pathVariablesSet;
     }
 
@@ -149,7 +151,7 @@ public class ShenyuTrieNode implements Serializable {
      *
      * @param pathVariablesSet pathVariablesSet
      */
-    public void setPathVariablesSet(final Cache<String, ShenyuTrieNode> 
pathVariablesSet) {
+    public void setPathVariablesSet(final Map<String, ShenyuTrieNode> 
pathVariablesSet) {
         this.pathVariablesSet = pathVariablesSet;
     }
 
@@ -175,7 +177,7 @@ public class ShenyuTrieNode implements Serializable {
      *
      * @param children children
      */
-    public void setChildren(final Cache<String, ShenyuTrieNode> children) {
+    public void setChildren(final Map<String, ShenyuTrieNode> children) {
         this.children = children;
     }
 
@@ -238,7 +240,7 @@ public class ShenyuTrieNode implements Serializable {
      *
      * @return rule cache
      */
-    public Cache<String, List<RuleData>> getPathRuleCache() {
+    public Map<String, List<RuleData>> getPathRuleCache() {
         return pathRuleCache;
     }
 
@@ -247,10 +249,28 @@ public class ShenyuTrieNode implements Serializable {
      *
      * @param pathRuleCache path rule cache
      */
-    public void setPathRuleCache(final Cache<String, List<RuleData>> 
pathRuleCache) {
+    public void setPathRuleCache(final Map<String, List<RuleData>> 
pathRuleCache) {
         this.pathRuleCache = pathRuleCache;
     }
     
+    /**
+     * get current node selector id.
+     *
+     * @return selectorId
+     */
+    public String getSelectorId() {
+        return selectorId;
+    }
+    
+    /**
+     * set current node selector id.
+     *
+     * @param selectorId selectorId
+     */
+    public void setSelectorId(final String selectorId) {
+        this.selectorId = selectorId;
+    }
+    
     @Override
     public boolean equals(final Object o) {
         if (this == o) {
@@ -263,12 +283,14 @@ public class ShenyuTrieNode implements Serializable {
         return isWildcard == that.isWildcard && endOfPath == that.endOfPath && 
matchStr.equals(that.matchStr)
                 && fullPath.equals(that.fullPath) && 
children.equals(that.children)
                 && pathVariablesSet.equals(that.pathVariablesSet) && 
pathVariableNode.equals(that.pathVariableNode)
-                && pathRuleCache.equals(that.pathRuleCache) && 
bizInfo.equals(that.bizInfo);
+                && pathRuleCache.equals(that.pathRuleCache) && 
bizInfo.equals(that.bizInfo)
+                && selectorId.equals(that.selectorId);
     }
     
     @Override
     public int hashCode() {
-        return Objects.hash(matchStr, fullPath, children, pathVariablesSet, 
pathVariableNode, isWildcard, endOfPath, pathRuleCache, bizInfo);
+        return Objects.hash(matchStr, fullPath, children, pathVariablesSet, 
pathVariableNode, isWildcard, endOfPath,
+                pathRuleCache, bizInfo, selectorId);
     }
     
     @Override
@@ -283,6 +305,7 @@ public class ShenyuTrieNode implements Serializable {
                 + ", endOfPath=" + endOfPath
                 + ", pathRuleCache=" + pathRuleCache
                 + ", bizInfo=" + bizInfo
+                + ", selectorId=" + selectorId
                 + '}';
     }
 }
diff --git 
a/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/cache/MatchDataCacheTest.java
 
b/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/cache/MatchDataCacheTest.java
index b5b49dae5..5b55cee1c 100644
--- 
a/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/cache/MatchDataCacheTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/cache/MatchDataCacheTest.java
@@ -52,7 +52,7 @@ public final class MatchDataCacheTest {
     public void testObtainSelectorData() throws NoSuchFieldException, 
IllegalAccessException {
         SelectorData firstSelectorData = 
SelectorData.builder().id("1").pluginName(mockPluginName1).sort(1).build();
         ConcurrentHashMap<String, WindowTinyLFUMap<String, SelectorData>> 
selectorMap = getFieldByName(selectorMapStr);
-        selectorMap.put(mockPluginName1, new WindowTinyLFUMap<>(100, 100, 
Boolean.TRUE));
+        selectorMap.put(mockPluginName1, new WindowTinyLFUMap<>(100, 100, 
Boolean.FALSE));
         selectorMap.get(mockPluginName1).put(path1, firstSelectorData);
         SelectorData firstSelectorDataCache = 
MatchDataCache.getInstance().obtainSelectorData(mockPluginName1, path1);
         assertEquals(firstSelectorData, firstSelectorDataCache);
@@ -90,7 +90,7 @@ public final class MatchDataCacheTest {
     public void testObtainRuleData() throws NoSuchFieldException, 
IllegalAccessException {
         RuleData cacheRuleData = 
RuleData.builder().id("1").pluginName(mockPluginName1).sort(1).build();
         ConcurrentHashMap<String, WindowTinyLFUMap<String, RuleData>> ruleMap 
= getFieldByName(ruleMapStr);
-        ruleMap.put(mockPluginName1, new WindowTinyLFUMap<>(100, 100, 
Boolean.TRUE));
+        ruleMap.put(mockPluginName1, new WindowTinyLFUMap<>(100, 100, 
Boolean.FALSE));
         ruleMap.get(mockPluginName1).put(path1, cacheRuleData);
         RuleData firstRuleDataCache = 
MatchDataCache.getInstance().obtainRuleData(mockPluginName1, path1);
         assertEquals(cacheRuleData, firstRuleDataCache);

Reply via email to