From 89c1e4f91de2a527ec825c76b0de5dd2fd42cc59 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期六, 13 八月 2022 11:30:33 +0800 Subject: [PATCH] update 重写 spring-cache 实现 更人性化的操作 支持注解指定ttl等一些参数 --- ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisCacheController.java | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 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 2312aab..7342cba 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,5 +1,6 @@ package com.ruoyi.demo.controller; +import com.ruoyi.common.constant.CacheNames; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.utils.redis.RedisUtils; import lombok.RequiredArgsConstructor; @@ -18,7 +19,7 @@ * @author Lion Li */ // 绫荤骇鍒� 缂撳瓨缁熶竴閰嶇疆 -//@CacheConfig(cacheNames = "redissonCacheMap") +//@CacheConfig(cacheNames = CacheNames.DEMO_CACHE) @RequiredArgsConstructor @RestController @RequestMapping("/demo/cache") @@ -36,9 +37,9 @@ * 閲嶇偣璇存槑: 缂撳瓨娉ㄨВ涓ヨ皑涓庡叾浠栫瓫閫夋暟鎹姛鑳戒竴璧蜂娇鐢� * 渚嬪: 鏁版嵁鏉冮檺娉ㄨВ 浼氶�犳垚 缂撳瓨鍑荤┛ 涓� 鏁版嵁涓嶄竴鑷撮棶棰� * <p> - * cacheNames 涓洪厤缃枃浠跺唴 groupId + * cacheNames 鍛藉悕瑙勫垯 鏌ョ湅 {@link CacheNames} 娉ㄩ噴 鏀寔澶氬弬鏁� */ - @Cacheable(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null") + @Cacheable(cacheNames = "demo:cache#60s#10m#20", key = "#key", condition = "#key != null") @GetMapping("/test1") public R<String> test1(String key, String value) { return R.ok("鎿嶄綔鎴愬姛", value); @@ -48,11 +49,11 @@ * 娴嬭瘯 @CachePut * <p> * 鍔犱簡@CachePut娉ㄨВ鐨勬柟娉�,浼氭妸鏂规硶鐨勮繑鍥炲�紁ut鍒扮紦瀛橀噷闈㈢紦瀛樿捣鏉�,渚涘叾瀹冨湴鏂逛娇鐢� - * 瀹冦�岄�氬父鐢ㄥ湪鏂板鏂规硶涓娿�� + * 瀹冦�岄�氬父鐢ㄥ湪鏂板鎴栬�呭疄鏃舵洿鏂版柟娉曚笂銆� * <p> - * cacheNames 涓� 閰嶇疆鏂囦欢鍐� groupId + * cacheNames 鍛藉悕瑙勫垯 鏌ョ湅 {@link CacheNames} 娉ㄩ噴 鏀寔澶氬弬鏁� */ - @CachePut(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null") + @CachePut(cacheNames = CacheNames.DEMO_CACHE, key = "#key", condition = "#key != null") @GetMapping("/test2") public R<String> test2(String key, String value) { return R.ok("鎿嶄綔鎴愬姛", value); @@ -62,11 +63,11 @@ * 娴嬭瘯 @CacheEvict * <p> * 浣跨敤浜咰acheEvict娉ㄨВ鐨勬柟娉�,浼氭竻绌烘寚瀹氱紦瀛� - * 銆屼竴鑸敤鍦ㄦ洿鏂版垨鑰呭垹闄ょ殑鏂规硶涓娿�� + * 銆屼竴鑸敤鍦ㄥ垹闄ょ殑鏂规硶涓娿�� * <p> - * cacheNames 涓� 閰嶇疆鏂囦欢鍐� groupId + * cacheNames 鍛藉悕瑙勫垯 鏌ョ湅 {@link CacheNames} 娉ㄩ噴 鏀寔澶氬弬鏁� */ - @CacheEvict(cacheNames = "redissonCacheMap", key = "#key", condition = "#key != null") + @CacheEvict(cacheNames = CacheNames.DEMO_CACHE, key = "#key", condition = "#key != null") @GetMapping("/test3") public R<String> test3(String key, String value) { return R.ok("鎿嶄綔鎴愬姛", value); -- Gitblit v1.9.3