From dd25573ebce3450d90d0012a30b12a5185bc7310 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期五, 08 七月 2022 15:49:15 +0800
Subject: [PATCH] update 使用 @param 注释替换 @Parameter 注解 fix 修复 token 无法传递 与 无法持久化问题

---
 ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisCacheController.java |  116 +++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 71 insertions(+), 45 deletions(-)

diff --git a/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisCacheController.java b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisCacheController.java
index 4588f13..a345167 100644
--- a/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisCacheController.java
+++ b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisCacheController.java
@@ -1,14 +1,17 @@
 package com.ruoyi.demo.controller;
 
-import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.utils.redis.RedisUtils;
+import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+
+import java.time.Duration;
 
 /**
  * spring-cache 婕旂ず妗堜緥
@@ -17,54 +20,77 @@
  */
 // 绫荤骇鍒� 缂撳瓨缁熶竴閰嶇疆
 //@CacheConfig(cacheNames = "redissonCacheMap")
-@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@Tag(name = "spring-cache 婕旂ず妗堜緥", description = "spring-cache 婕旂ず妗堜緥")
+@RequiredArgsConstructor
 @RestController
 @RequestMapping("/demo/cache")
 public class RedisCacheController {
 
-	/**
-	 * 娴嬭瘯 @Cacheable
-	 *
-	 * 琛ㄧず杩欎釜鏂规硶鏈変簡缂撳瓨鐨勫姛鑳�,鏂规硶鐨勮繑鍥炲�间細琚紦瀛樹笅鏉�
-	 * 涓嬩竴娆¤皟鐢ㄨ鏂规硶鍓�,浼氬幓妫�鏌ユ槸鍚︾紦瀛樹腑宸茬粡鏈夊��
-	 * 濡傛灉鏈夊氨鐩存帴杩斿洖,涓嶈皟鐢ㄦ柟娉�
-	 * 濡傛灉娌℃湁,灏辫皟鐢ㄦ柟娉�,鐒跺悗鎶婄粨鏋滅紦瀛樿捣鏉�
-	 * 杩欎釜娉ㄨВ銆屼竴鑸敤鍦ㄦ煡璇㈡柟娉曚笂銆�
-	 *
-	 * cacheNames 涓洪厤缃枃浠跺唴 groupId
-	 */
-	@Cacheable(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null")
-	@GetMapping("/test1")
-	public AjaxResult<String> test1(String key, String value){
-		return AjaxResult.success("鎿嶄綔鎴愬姛", value);
-	}
+    /**
+     * 娴嬭瘯 @Cacheable
+     * <p>
+     * 琛ㄧず杩欎釜鏂规硶鏈変簡缂撳瓨鐨勫姛鑳�,鏂规硶鐨勮繑鍥炲�间細琚紦瀛樹笅鏉�
+     * 涓嬩竴娆¤皟鐢ㄨ鏂规硶鍓�,浼氬幓妫�鏌ユ槸鍚︾紦瀛樹腑宸茬粡鏈夊��
+     * 濡傛灉鏈夊氨鐩存帴杩斿洖,涓嶈皟鐢ㄦ柟娉�
+     * 濡傛灉娌℃湁,灏辫皟鐢ㄦ柟娉�,鐒跺悗鎶婄粨鏋滅紦瀛樿捣鏉�
+     * 杩欎釜娉ㄨВ銆屼竴鑸敤鍦ㄦ煡璇㈡柟娉曚笂銆�
+     * <p>
+     * 閲嶇偣璇存槑: 缂撳瓨娉ㄨВ涓ヨ皑涓庡叾浠栫瓫閫夋暟鎹姛鑳戒竴璧蜂娇鐢�
+     * 渚嬪: 鏁版嵁鏉冮檺娉ㄨВ 浼氶�犳垚 缂撳瓨鍑荤┛ 涓� 鏁版嵁涓嶄竴鑷撮棶棰�
+     * <p>
+     * cacheNames 涓洪厤缃枃浠跺唴 groupId
+     */
+    @Cacheable(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null")
+    @GetMapping("/test1")
+    public R<String> test1(String key, String value) {
+        return R.ok("鎿嶄綔鎴愬姛", value);
+    }
 
-	/**
-	 * 娴嬭瘯 @CachePut
-	 *
-	 * 鍔犱簡@CachePut娉ㄨВ鐨勬柟娉�,浼氭妸鏂规硶鐨勮繑鍥炲�紁ut鍒扮紦瀛橀噷闈㈢紦瀛樿捣鏉�,渚涘叾瀹冨湴鏂逛娇鐢�
-	 * 瀹冦�岄�氬父鐢ㄥ湪鏂板鏂规硶涓娿��
-	 *
-	 * cacheNames 涓� 閰嶇疆鏂囦欢鍐� groupId
-	 */
-	@CachePut(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null")
-	@GetMapping("/test2")
-	public AjaxResult<String> test2(String key, String value){
-		return AjaxResult.success("鎿嶄綔鎴愬姛", value);
-	}
+    /**
+     * 娴嬭瘯 @CachePut
+     * <p>
+     * 鍔犱簡@CachePut娉ㄨВ鐨勬柟娉�,浼氭妸鏂规硶鐨勮繑鍥炲�紁ut鍒扮紦瀛橀噷闈㈢紦瀛樿捣鏉�,渚涘叾瀹冨湴鏂逛娇鐢�
+     * 瀹冦�岄�氬父鐢ㄥ湪鏂板鏂规硶涓娿��
+     * <p>
+     * cacheNames 涓� 閰嶇疆鏂囦欢鍐� groupId
+     */
+    @CachePut(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null")
+    @GetMapping("/test2")
+    public R<String> test2(String key, String value) {
+        return R.ok("鎿嶄綔鎴愬姛", value);
+    }
 
-	/**
-	 * 娴嬭瘯 @CacheEvict
-	 *
-	 * 浣跨敤浜咰acheEvict娉ㄨВ鐨勬柟娉�,浼氭竻绌烘寚瀹氱紦瀛�
-	 * 銆屼竴鑸敤鍦ㄦ洿鏂版垨鑰呭垹闄ょ殑鏂规硶涓娿��
-	 *
-	 * cacheNames 涓� 閰嶇疆鏂囦欢鍐� groupId
-	 */
-	@CacheEvict(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null")
-	@GetMapping("/test3")
-	public AjaxResult<String> test3(String key, String value){
-		return AjaxResult.success("鎿嶄綔鎴愬姛", value);
-	}
+    /**
+     * 娴嬭瘯 @CacheEvict
+     * <p>
+     * 浣跨敤浜咰acheEvict娉ㄨВ鐨勬柟娉�,浼氭竻绌烘寚瀹氱紦瀛�
+     * 銆屼竴鑸敤鍦ㄦ洿鏂版垨鑰呭垹闄ょ殑鏂规硶涓娿��
+     * <p>
+     * cacheNames 涓� 閰嶇疆鏂囦欢鍐� groupId
+     */
+    @CacheEvict(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null")
+    @GetMapping("/test3")
+    public R<String> test3(String key, String value) {
+        return R.ok("鎿嶄綔鎴愬姛", value);
+    }
+
+    /**
+     * 娴嬭瘯璁剧疆杩囨湡鏃堕棿
+     * 鎵嬪姩璁剧疆杩囨湡鏃堕棿10绉�
+     * 11绉掑悗鑾峰彇 鍒ゆ柇鏄惁鐩哥瓑
+     */
+    @GetMapping("/test6")
+    public R<Boolean> test6(String key, String value) {
+        RedisUtils.setCacheObject(key, value);
+        boolean flag = RedisUtils.expire(key, Duration.ofSeconds(10));
+        System.out.println("***********" + flag);
+        try {
+            Thread.sleep(11 * 1000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        Object obj = RedisUtils.getCacheObject(key);
+        return R.ok(value.equals(obj));
+    }
 
 }

--
Gitblit v1.9.3