diff --git a/apps/threat-detection/pom.xml b/apps/threat-detection/pom.xml
index e5e5cd3e2c..e642895817 100644
--- a/apps/threat-detection/pom.xml
+++ b/apps/threat-detection/pom.xml
@@ -132,6 +132,12 @@
2.24.2
+
+ com.github.ben-manes.caffeine
+ caffeine
+ 2.9.3
+
+
diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/CounterCache.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/CounterCache.java
index f1eaeffa90..08efe0f1a7 100644
--- a/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/CounterCache.java
+++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/CounterCache.java
@@ -10,5 +10,5 @@ public interface CounterCache {
boolean exists(String key);
- void clear(String key);
+ void reset(String key);
}
diff --git a/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/RedisBackedCounterCache.java b/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/RedisBackedCounterCache.java
new file mode 100644
index 0000000000..6d053c6be7
--- /dev/null
+++ b/apps/threat-detection/src/main/java/com/akto/threat/detection/cache/RedisBackedCounterCache.java
@@ -0,0 +1,109 @@
+package com.akto.threat.detection.cache;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import io.lettuce.core.RedisClient;
+import io.lettuce.core.api.StatefulRedisConnection;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.*;
+
+public class RedisBackedCounterCache implements CounterCache {
+ private final StatefulRedisConnection redis;
+
+ private final Cache localCache;
+
+ private final String prefix;
+ private final ConcurrentLinkedQueue