This is an automated email from the ASF dual-hosted git repository.
liuhongyu 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 c8e89a4952 Added cache MD5 judgment (#5995)
c8e89a4952 is described below
commit c8e89a4952bac2ea84947d68f7f6c93b3b604138
Author: JerryDtj <[email protected]>
AuthorDate: Mon Apr 7 15:00:33 2025 +0800
Added cache MD5 judgment (#5995)
* 添加重试策略
* http请求重试策略重构
* http请求重试策略重构,添加Customer,retryBackOff,fixed三种策略
* http请求重试策略重构,添加Customer,retryBackOff,fixed三种策略
* http请求重试策略重构,添加Customer,retryBackOff,fixed三种策略
* 修复格式
* 中文转英文
* add license header
* add license header
* add license header
* add license header
* 修复代码格式化问题
* fix testFixedRetryStrategyExecute bug
* 增加根据md5获取缓存判断逻辑.
---------
Co-authored-by: aias00 <[email protected]>
---
.../admin/listener/AbstractDataChangedListener.java | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/AbstractDataChangedListener.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/AbstractDataChangedListener.java
index fd55ee0031..1a260930cb 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/AbstractDataChangedListener.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/AbstractDataChangedListener.java
@@ -18,6 +18,10 @@
package org.apache.shenyu.admin.listener;
import jakarta.annotation.Resource;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -46,10 +50,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
import static
org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID;
@@ -297,8 +297,16 @@ public abstract class AbstractDataChangedListener
implements DataChangedListener
*/
protected <T> void updateCache(final ConfigGroupEnum group, final List<T>
data, final String namespaceId) {
String json = GsonUtils.getInstance().toJson(data);
+ String newMd5 = DigestUtils.md5Hex(json);
+ ConfigDataCache oldConfig =
CACHE.get(HttpLongPollingDataChangedListener.buildCacheKey(namespaceId,
group.name()));
+ if (Objects.nonNull(oldConfig) &&
StringUtils.isNotBlank(oldConfig.getMd5())) {
+ if (oldConfig.getMd5().equals(newMd5)) {
+ LOG.info("config cache[{}] is not changed, skip update.",
group);
+ return;
+ }
+ }
String configDataCacheKey =
HttpLongPollingDataChangedListener.buildCacheKey(namespaceId, group.name());
- ConfigDataCache newVal = new ConfigDataCache(configDataCacheKey, json,
DigestUtils.md5Hex(json), System.currentTimeMillis(), namespaceId);
+ ConfigDataCache newVal = new ConfigDataCache(configDataCacheKey, json,
newMd5, System.currentTimeMillis(), namespaceId);
ConfigDataCache oldVal = CACHE.put(newVal.getGroup(), newVal);
LOG.info("update config cache[{}], old: {}, updated: {}", group,
oldVal, newVal);
}