diff --git a/pom.xml b/pom.xml
index cd36ec726c..24f73600cb 100755
--- a/pom.xml
+++ b/pom.xml
@@ -43,6 +43,7 @@
1.2.83_noneautotype
1.3.2
+ 2.9.3
4.12
@@ -219,6 +220,11 @@
${powermock.version}
test
+
+ com.github.ben-manes.caffeine
+ caffeine
+ ${caffeine.version}
+
diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/TokenCacheNode.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/TokenCacheNode.java
index be734ad306..3bf7fbd3e5 100644
--- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/TokenCacheNode.java
+++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/TokenCacheNode.java
@@ -21,7 +21,7 @@
/**
* We use TokenCacheNodeManager to store the tokenId, whose the underlying storage structure
- * is ConcurrentLinkedHashMap, Its storage node is TokenCacheNode. In order to operate the nowCalls value when
+ * is Caffeine, Its storage node is TokenCacheNode. In order to operate the nowCalls value when
* the expired tokenId is deleted regularly, we need to store the flowId in TokenCacheNode.
*
* @author yunfeiyanggzq
diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/TokenCacheNodeManager.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/TokenCacheNodeManager.java
index 890f62e6da..2fe3ef5c16 100644
--- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/TokenCacheNodeManager.java
+++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/TokenCacheNodeManager.java
@@ -16,9 +16,9 @@
package com.alibaba.csp.sentinel.cluster.flow.statistic.concurrent;
import com.alibaba.csp.sentinel.cluster.flow.statistic.concurrent.expire.RegularExpireStrategy;
+import com.alibaba.csp.sentinel.slots.statistic.cache.CacheMap;
+import com.alibaba.csp.sentinel.slots.statistic.cache.CaffeineCacheMapWrapper;
import com.alibaba.csp.sentinel.util.AssertUtil;
-import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
-import com.googlecode.concurrentlinkedhashmap.Weighers;
import java.util.Set;
@@ -26,7 +26,7 @@
* @author yunfeiyanggzq
*/
public class TokenCacheNodeManager {
- private static ConcurrentLinkedHashMap TOKEN_CACHE_NODE_MAP;
+ private static CacheMap TOKEN_CACHE_NODE_MAP;
private static final int DEFAULT_CONCURRENCY_LEVEL = 16;
@@ -40,11 +40,7 @@ public static void prepare(int concurrencyLevel, int maximumWeightedCapacity) {
AssertUtil.isTrue(concurrencyLevel > 0, "concurrencyLevel must be positive");
AssertUtil.isTrue(maximumWeightedCapacity > 0, "maximumWeightedCapacity must be positive");
- TOKEN_CACHE_NODE_MAP = new ConcurrentLinkedHashMap.Builder()
- .concurrencyLevel(concurrencyLevel)
- .maximumWeightedCapacity(maximumWeightedCapacity)
- .weigher(Weighers.singleton())
- .build();
+ TOKEN_CACHE_NODE_MAP = new CaffeineCacheMapWrapper<>(maximumWeightedCapacity);
// Start the task of regularly clearing expired keys
RegularExpireStrategy strategy = new RegularExpireStrategy(TOKEN_CACHE_NODE_MAP);
strategy.startClearTaskRegularly();
@@ -52,8 +48,7 @@ public static void prepare(int concurrencyLevel, int maximumWeightedCapacity) {
public static TokenCacheNode getTokenCacheNode(long tokenId) {
- //use getQuietly to prevent disorder
- return TOKEN_CACHE_NODE_MAP.getQuietly(tokenId);
+ return TOKEN_CACHE_NODE_MAP.get(tokenId);
}
public static void putTokenCacheNode(long tokenId, TokenCacheNode cacheNode) {
@@ -69,7 +64,7 @@ public static TokenCacheNode removeTokenCacheNode(long tokenId) {
}
public static int getSize() {
- return TOKEN_CACHE_NODE_MAP.size();
+ return (int) TOKEN_CACHE_NODE_MAP.size();
}
public static Set getCacheKeySet() {
diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/expire/RegularExpireStrategy.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/expire/RegularExpireStrategy.java
index 24fd42fbfc..6e388fd7d2 100644
--- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/expire/RegularExpireStrategy.java
+++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/concurrent/expire/RegularExpireStrategy.java
@@ -21,8 +21,8 @@
import com.alibaba.csp.sentinel.cluster.server.connection.ConnectionManager;
import com.alibaba.csp.sentinel.concurrent.NamedThreadFactory;
import com.alibaba.csp.sentinel.log.RecordLog;
+import com.alibaba.csp.sentinel.slots.statistic.cache.CacheMap;
import com.alibaba.csp.sentinel.util.AssertUtil;
-import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import java.util.ArrayList;
import java.util.List;
@@ -62,14 +62,14 @@ public class RegularExpireStrategy implements ExpireStrategy {
/**
* the local cache of tokenId
*/
- private ConcurrentLinkedHashMap localCache;
+ private CacheMap localCache;
@SuppressWarnings("PMD.ThreadPoolCreationRule")
private static ScheduledExecutorService executor = Executors.newScheduledThreadPool(1,
new NamedThreadFactory("regular clear expired token thread", true));
- public RegularExpireStrategy(ConcurrentLinkedHashMap localCache) {
+ public RegularExpireStrategy(CacheMap localCache) {
AssertUtil.isTrue(localCache != null, " local cache can't be null");
this.localCache = localCache;
}
diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParameterLeapArray.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParameterLeapArray.java
index 2b5fabc4e7..b71b737b80 100644
--- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParameterLeapArray.java
+++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/flow/statistic/metric/ClusterParameterLeapArray.java
@@ -18,7 +18,7 @@
import com.alibaba.csp.sentinel.slots.statistic.base.LeapArray;
import com.alibaba.csp.sentinel.slots.statistic.base.WindowWrap;
import com.alibaba.csp.sentinel.slots.statistic.cache.CacheMap;
-import com.alibaba.csp.sentinel.slots.statistic.cache.ConcurrentLinkedHashMapWrapper;
+import com.alibaba.csp.sentinel.slots.statistic.cache.CaffeineCacheMapWrapper;
import com.alibaba.csp.sentinel.util.AssertUtil;
/**
@@ -38,7 +38,7 @@ public ClusterParameterLeapArray(int sampleCount, int intervalInMs, int maxCapac
@Override
public CacheMap