From 3c8d864b5f68af5167199e0d5c9ff6c0c5852638 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期一, 20 一月 2025 11:35:45 +0800
Subject: [PATCH] !639 发布 5.3.0-BETA 公测版本 Merge pull request !639 from 疯狂的狮子Li/dev

---
 ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/core/dao/PlusSaTokenDao.java |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/core/dao/PlusSaTokenDao.java b/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/core/dao/PlusSaTokenDao.java
index b262d07..a2a1520 100644
--- a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/core/dao/PlusSaTokenDao.java
+++ b/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/core/dao/PlusSaTokenDao.java
@@ -2,7 +2,6 @@
 
 import cn.dev33.satoken.dao.SaTokenDao;
 import cn.dev33.satoken.util.SaFoxUtil;
-import cn.hutool.core.lang.Console;
 import com.github.benmanes.caffeine.cache.Cache;
 import com.github.benmanes.caffeine.cache.Caffeine;
 import org.dromara.common.redis.utils.RedisUtils;
@@ -15,6 +14,8 @@
 
 /**
  * Sa-Token鎸佷箙灞傛帴鍙�(浣跨敤妗嗘灦鑷甫RedisUtils瀹炵幇 鍗忚缁熶竴)
+ * <p>
+ * 閲囩敤 caffeine + redis 澶氱骇缂撳瓨 浼樺寲骞跺彂鏌ヨ鏁堢巼
  *
  * @author Lion Li
  */
@@ -22,7 +23,7 @@
 
     private static final Cache<String, Object> CAFFEINE = Caffeine.newBuilder()
         // 璁剧疆鏈�鍚庝竴娆″啓鍏ユ垨璁块棶鍚庣粡杩囧浐瀹氭椂闂磋繃鏈�
-        .expireAfterWrite(10, TimeUnit.SECONDS)
+        .expireAfterWrite(5, TimeUnit.SECONDS)
         // 鍒濆鐨勭紦瀛樼┖闂村ぇ灏�
         .initialCapacity(100)
         // 缂撳瓨鐨勬渶澶ф潯鏁�
@@ -35,7 +36,6 @@
     @Override
     public String get(String key) {
         Object o = CAFFEINE.get(key, k -> RedisUtils.getCacheObject(key));
-        Console.log("caffeine -> key:" + key + ",value:" + o);
         return (String) o;
     }
 
@@ -51,9 +51,13 @@
         if (timeout == NEVER_EXPIRE) {
             RedisUtils.setCacheObject(key, value);
         } else {
-            RedisUtils.setCacheObject(key, value, Duration.ofSeconds(timeout));
+            if (RedisUtils.hasKey(key)) {
+                RedisUtils.setCacheObject(key, value, true);
+            } else {
+                RedisUtils.setCacheObject(key, value, Duration.ofSeconds(timeout));
+            }
         }
-        CAFFEINE.put(key, value);
+        CAFFEINE.invalidate(key);
     }
 
     /**
@@ -63,7 +67,7 @@
     public void update(String key, String value) {
         if (RedisUtils.hasKey(key)) {
             RedisUtils.setCacheObject(key, value, true);
-            CAFFEINE.put(key, value);
+            CAFFEINE.invalidate(key);
         }
     }
 
@@ -99,7 +103,6 @@
     @Override
     public Object getObject(String key) {
         Object o = CAFFEINE.get(key, k -> RedisUtils.getCacheObject(key));
-        Console.log("caffeine -> key:" + key + ",value:" + o);
         return o;
     }
 
@@ -115,9 +118,13 @@
         if (timeout == NEVER_EXPIRE) {
             RedisUtils.setCacheObject(key, object);
         } else {
-            RedisUtils.setCacheObject(key, object, Duration.ofSeconds(timeout));
+            if (RedisUtils.hasKey(key)) {
+                RedisUtils.setCacheObject(key, object, true);
+            } else {
+                RedisUtils.setCacheObject(key, object, Duration.ofSeconds(timeout));
+            }
         }
-        CAFFEINE.put(key, object);
+        CAFFEINE.invalidate(key);
     }
 
     /**
@@ -127,7 +134,7 @@
     public void updateObject(String key, Object object) {
         if (RedisUtils.hasKey(key)) {
             RedisUtils.setCacheObject(key, object, true);
-            CAFFEINE.put(key, object);
+            CAFFEINE.invalidate(key);
         }
     }
 

--
Gitblit v1.9.3