From b528f0bd146769407de4b7da223e75d46b51d345 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期五, 24 一月 2025 13:06:31 +0800 Subject: [PATCH] 🧨🧨🧨发布 5.3.0 新春版 祝大家新年快乐 --- ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/manager/CaffeineCacheDecorator.java | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 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 7d3ab42..6e83df1 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 @@ -1,6 +1,5 @@ package org.dromara.common.redis.manager; -import cn.hutool.core.lang.Console; import org.dromara.common.core.utils.SpringUtils; import org.springframework.cache.Cache; @@ -16,15 +15,17 @@ private static final com.github.benmanes.caffeine.cache.Cache<Object, Object> CAFFEINE = SpringUtils.getBean("caffeine"); + private final String name; private final Cache cache; - public CaffeineCacheDecorator(Cache cache) { + public CaffeineCacheDecorator(String name, Cache cache) { + this.name = name; this.cache = cache; } @Override public String getName() { - return cache.getName(); + return name; } @Override @@ -33,7 +34,7 @@ } public String getUniqueKey(Object key) { - return cache.getName() + ":" + key; + return name + ":" + key; } @Override @@ -43,6 +44,7 @@ } @SuppressWarnings("unchecked") + @Override public <T> T get(Object key, Class<T> type) { Object o = CAFFEINE.get(getUniqueKey(key), k -> cache.get(key, type)); return (T) o; @@ -50,10 +52,13 @@ @Override public void put(Object key, Object value) { + CAFFEINE.invalidate(getUniqueKey(key)); cache.put(key, value); } + @Override public ValueWrapper putIfAbsent(Object key, Object value) { + CAFFEINE.invalidate(getUniqueKey(key)); return cache.putIfAbsent(key, value); } @@ -62,6 +67,7 @@ evictIfPresent(key); } + @Override public boolean evictIfPresent(Object key) { boolean b = cache.evictIfPresent(key); if (b) { @@ -75,6 +81,7 @@ cache.clear(); } + @Override public boolean invalidate() { return cache.invalidate(); } -- Gitblit v1.9.3