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

Aias00 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 ff08c1727a fix(tars): clear companion caches on invalidation (#7159)
ff08c1727a is described below

commit ff08c1727a47dced6c3dce01e135db0a6ccb51db
Author: Liming Deng <[email protected]>
AuthorDate: Wed Sep 30 09:58:21 2026 +0800

    fix(tars): clear companion caches on invalidation (#7159)
---
 .../plugin/tars/cache/ApplicationConfigCache.java  | 12 +++++--
 .../tars/cache/ApplicationConfigCacheTest.java     | 39 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/main/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCache.java
 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/main/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCache.java
index 6bd72c4896..aba526b390 100644
--- 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/main/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCache.java
+++ 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/main/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCache.java
@@ -341,8 +341,16 @@ public final class ApplicationConfigCache {
      * @param contextPath context path
      */
     public void invalidate(final String contextPath) {
-        List<MetaData> metaDataList = ctxPathCache.getOrDefault(contextPath, 
new ArrayList<>());
-        metaDataList.forEach(metaData -> cache.invalidate(metaData.getPath()));
+        List<MetaData> metaDataList = ctxPathCache.remove(contextPath);
+        if (CollectionUtils.isNotEmpty(metaDataList)) {
+            metaDataList.forEach(metaData -> {
+                cache.invalidate(metaData.getPath());
+                prxClassCache.remove(metaData.getPath());
+                String paramKeyPrefix = PrxInfoUtil.getPrxName(metaData) + "_";
+                prxParamCache.keySet().removeIf(key -> 
key.startsWith(paramKeyPrefix));
+            });
+        }
+        refreshUpstreamCache.remove(contextPath);
     }
     
     /**
diff --git 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java
 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java
index eadccbb998..d4ee86e2b5 100644
--- 
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java
@@ -32,7 +32,9 @@ import org.mockito.junit.jupiter.MockitoExtension;
 
 import java.lang.reflect.Field;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -41,6 +43,7 @@ import java.util.concurrent.locks.ReentrantLock;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -171,4 +174,40 @@ public final class ApplicationConfigCacheTest {
         final ApplicationConfigCache result = 
ApplicationConfigCache.getInstance();
         assertNotNull(result);
     }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testInvalidateRemovesCompanionCaches() throws Exception {
+        final MetaData metaData = new MetaData("id", "127.0.0.1:8080", 
"/demo", "/demo/test",
+                RpcTypeEnum.TARS.getName(), "service", "method", "", "", 
false, Constants.SYS_DEFAULT_NAMESPACE_ID);
+        final Map<String, List<MetaData>> ctxPathCache = (Map<String, 
List<MetaData>>) getField("ctxPathCache");
+        final Map<String, Class<?>> prxClassCache = (Map<String, Class<?>>) 
getField("prxClassCache");
+        final Map<String, ApplicationConfigCache.TarsParamInfo> prxParamCache =
+                (Map<String, ApplicationConfigCache.TarsParamInfo>) 
getField("prxParamCache");
+        final Map<String, List<?>> refreshUpstreamCache = (Map<String, 
List<?>>) getField("refreshUpstreamCache");
+        ctxPathCache.clear();
+        prxClassCache.clear();
+        prxParamCache.clear();
+        refreshUpstreamCache.clear();
+        ctxPathCache.put(metaData.getContextPath(), 
Collections.singletonList(metaData));
+        prxClassCache.put(metaData.getPath(), 
ApplicationConfigCacheTest.class);
+        final String paramKey = PrxInfoUtil.getPrxName(metaData) + "_" + 
metaData.getMethodName();
+        prxParamCache.put(paramKey, new 
ApplicationConfigCache.TarsParamInfo(new Class<?>[0], new String[0]));
+        refreshUpstreamCache.put(metaData.getContextPath(), 
Collections.emptyList());
+        final TarsInvokePrxList cached = 
applicationConfigCacheUnderTest.get(metaData.getPath());
+
+        applicationConfigCacheUnderTest.invalidate(metaData.getContextPath());
+
+        assertTrue(ctxPathCache.isEmpty());
+        assertTrue(prxClassCache.isEmpty());
+        assertTrue(prxParamCache.isEmpty());
+        assertTrue(refreshUpstreamCache.isEmpty());
+        assertNotSame(cached, 
applicationConfigCacheUnderTest.get(metaData.getPath()));
+    }
+
+    private Object getField(final String fieldName) throws 
NoSuchFieldException, IllegalAccessException {
+        java.lang.reflect.Field field = 
ApplicationConfigCache.class.getDeclaredField(fieldName);
+        field.setAccessible(true);
+        return field.get(applicationConfigCacheUnderTest);
+    }
 }

Reply via email to