From 132597214153d802132e649fc1a815e0095e25c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Thu, 11 Jan 2024 23:23:43 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20caffeine=E5=85=B1?= =?UTF-8?q?=E4=BA=AB=20key=E5=86=B2=E7=AA=81=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../redis/manager/CaffeineCacheDecorator.java | 18 +++++++++++------- 1 file 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 1d02efda..8d1f518f 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 @@ public class CaffeineCacheDecorator implements Cache { 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 get(Object key, Class 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 class CaffeineCacheDecorator implements Cache { 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 @@ public class CaffeineCacheDecorator implements Cache { @SuppressWarnings("unchecked") @Override public T get(Object key, Callable 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; }