From fcabba1087634e2e2fe22be7c15f85858f9a6558 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期四, 11 一月 2024 23:18:16 +0800
Subject: [PATCH] fix 修复 caffeine共享 key冲突导致的数据问题
---
ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/manager/CaffeineCacheDecorator.java | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/manager/CaffeineCacheDecorator.java b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/manager/CaffeineCacheDecorator.java
index 1d02efd..8d1f518 100644
--- a/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/manager/CaffeineCacheDecorator.java
+++ b/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/manager/CaffeineCacheDecorator.java
@@ -32,17 +32,21 @@
return cache.getNativeCache();
}
+ public String getUniqueKey(Object key) {
+ return cache.getName() + ":" + key;
+ }
+
@Override
public ValueWrapper get(Object key) {
- Object o = CAFFEINE.get(key, k -> cache.get(key));
- Console.log("redisson caffeine -> key: " + key + ",value:" + o);
+ Object o = CAFFEINE.get(getUniqueKey(key), k -> cache.get(key));
+ Console.log("redisson caffeine -> key: " + getUniqueKey(key) + ",value:" + o);
return (ValueWrapper) o;
}
@SuppressWarnings("unchecked")
public <T> T get(Object key, Class<T> type) {
- Object o = CAFFEINE.get(key, k -> cache.get(key, type));
- Console.log("redisson caffeine -> key: " + key + ",value:" + o);
+ Object o = CAFFEINE.get(getUniqueKey(key), k -> cache.get(key, type));
+ Console.log("redisson caffeine -> key: " + getUniqueKey(key) + ",value:" + o);
return (T) o;
}
@@ -63,7 +67,7 @@
public boolean evictIfPresent(Object key) {
boolean b = cache.evictIfPresent(key);
if (b) {
- CAFFEINE.invalidate(key);
+ CAFFEINE.invalidate(getUniqueKey(key));
}
return b;
}
@@ -80,8 +84,8 @@
@SuppressWarnings("unchecked")
@Override
public <T> T get(Object key, Callable<T> valueLoader) {
- Object o = CAFFEINE.get(key, k -> cache.get(key, valueLoader));
- Console.log("redisson caffeine -> key: " + key + ",value:" + o);
+ Object o = CAFFEINE.get(getUniqueKey(key), k -> cache.get(key, valueLoader));
+ Console.log("redisson caffeine -> key: " + getUniqueKey(key) + ",value:" + o);
return (T) o;
}
--
Gitblit v1.9.3