Browse Source

remove redis

allen 1 month ago
parent
commit
97ed1216c3
21 changed files with 847 additions and 702 deletions
  1. 1 10
      fdapfe-admin/src/main/java/com/cn/fdapfe/RuoYiApplication.java
  2. 4 3
      fdapfe-admin/src/main/java/com/cn/fdapfe/web/controller/common/CaptchaController.java
  3. 121 121
      fdapfe-admin/src/main/java/com/cn/fdapfe/web/controller/monitor/CacheController.java
  4. 6 5
      fdapfe-admin/src/main/java/com/cn/fdapfe/web/controller/monitor/SysUserOnlineController.java
  5. 2 2
      fdapfe-admin/src/main/resources/application-druid.yml
  6. 26 23
      fdapfe-admin/src/main/resources/application.yml
  7. 8 3
      fdapfe-common/pom.xml
  8. 123 0
      fdapfe-common/src/main/java/com/cn/fdapfe/common/core/redis/CaffeineCache.java
  9. 268 268
      fdapfe-common/src/main/java/com/cn/fdapfe/common/core/redis/RedisCache.java
  10. 5 6
      fdapfe-common/src/main/java/com/cn/fdapfe/common/utils/DictUtils.java
  11. 87 89
      fdapfe-framework/src/main/java/com/cn/fdapfe/framework/aspectj/RateLimiterAspect.java
  12. 23 0
      fdapfe-framework/src/main/java/com/cn/fdapfe/framework/config/CaffeineConfig.java
  13. 52 52
      fdapfe-framework/src/main/java/com/cn/fdapfe/framework/config/FastJson2JsonRedisSerializer.java
  14. 69 69
      fdapfe-framework/src/main/java/com/cn/fdapfe/framework/config/RedisConfig.java
  15. 5 4
      fdapfe-framework/src/main/java/com/cn/fdapfe/framework/interceptor/impl/SameUrlDataInterceptor.java
  16. 13 16
      fdapfe-framework/src/main/java/com/cn/fdapfe/framework/web/service/SysLoginService.java
  17. 12 11
      fdapfe-framework/src/main/java/com/cn/fdapfe/framework/web/service/SysPasswordService.java
  18. 4 4
      fdapfe-framework/src/main/java/com/cn/fdapfe/framework/web/service/SysRegisterService.java
  19. 6 5
      fdapfe-framework/src/main/java/com/cn/fdapfe/framework/web/service/TokenService.java
  20. 11 11
      fdapfe-system/src/main/java/com/cn/fdapfe/system/service/impl/SysConfigServiceImpl.java
  21. 1 0
      sql/createDB.sql

+ 1 - 10
fdapfe-admin/src/main/java/com/cn/fdapfe/RuoYiApplication.java

@@ -16,15 +16,6 @@ public class RuoYiApplication
     {
         // System.setProperty("spring.devtools.restart.enabled", "false");
         SpringApplication.run(RuoYiApplication.class, args);
-        System.out.println("(♥◠‿◠)ノ゙  若依启动成功   ლ(´ڡ`ლ)゙  \n" +
-                " .-------.       ____     __        \n" +
-                " |  _ _   \\      \\   \\   /  /    \n" +
-                " | ( ' )  |       \\  _. /  '       \n" +
-                " |(_ o _) /        _( )_ .'         \n" +
-                " | (_,_).' __  ___(_ o _)'          \n" +
-                " |  |\\ \\  |  ||   |(_,_)'         \n" +
-                " |  | \\ `'   /|   `-'  /           \n" +
-                " |  |  \\    /  \\      /           \n" +
-                " ''-'   `'-'    `-..-'              ");
+        System.out.println("(♥◠‿◠)ノ゙  后台启动成功   ლ(´ڡ`ლ)゙  ");
     }
 }

+ 4 - 3
fdapfe-admin/src/main/java/com/cn/fdapfe/web/controller/common/CaptchaController.java

@@ -6,6 +6,8 @@ import java.util.concurrent.TimeUnit;
 import javax.annotation.Resource;
 import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
+
+import com.cn.fdapfe.common.core.redis.CaffeineCache;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.FastByteArrayOutputStream;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -15,7 +17,6 @@ import com.cn.fdapfe.common.config.RuoYiConfig;
 import com.cn.fdapfe.common.constant.CacheConstants;
 import com.cn.fdapfe.common.constant.Constants;
 import com.cn.fdapfe.common.core.domain.AjaxResult;
-import com.cn.fdapfe.common.core.redis.RedisCache;
 import com.cn.fdapfe.common.utils.sign.Base64;
 import com.cn.fdapfe.common.utils.uuid.IdUtils;
 import com.cn.fdapfe.system.service.ISysConfigService;
@@ -35,7 +36,7 @@ public class CaptchaController
     private Producer captchaProducerMath;
 
     @Autowired
-    private RedisCache redisCache;
+    private CaffeineCache caffeineCache;
     
     @Autowired
     private ISysConfigService configService;
@@ -75,7 +76,7 @@ public class CaptchaController
             image = captchaProducer.createImage(capStr);
         }
 
-        redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
+        caffeineCache.setCacheWithExpiration(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
         // 转换流信息写出
         FastByteArrayOutputStream os = new FastByteArrayOutputStream();
         try

+ 121 - 121
fdapfe-admin/src/main/java/com/cn/fdapfe/web/controller/monitor/CacheController.java

@@ -1,121 +1,121 @@
-package com.cn.fdapfe.web.controller.monitor;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.TreeSet;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisCallback;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import com.cn.fdapfe.common.constant.CacheConstants;
-import com.cn.fdapfe.common.core.domain.AjaxResult;
-import com.cn.fdapfe.common.utils.StringUtils;
-import com.cn.fdapfe.system.domain.SysCache;
-
-/**
- * 缓存监控
- * 
- * @author ruoyi
- */
-@RestController
-@RequestMapping("/monitor/cache")
-public class CacheController
-{
-    @Autowired
-    private RedisTemplate<String, String> redisTemplate;
-
-    private final static List<SysCache> caches = new ArrayList<SysCache>();
-    {
-        caches.add(new SysCache(CacheConstants.LOGIN_TOKEN_KEY, "用户信息"));
-        caches.add(new SysCache(CacheConstants.SYS_CONFIG_KEY, "配置信息"));
-        caches.add(new SysCache(CacheConstants.SYS_DICT_KEY, "数据字典"));
-        caches.add(new SysCache(CacheConstants.CAPTCHA_CODE_KEY, "验证码"));
-        caches.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "防重提交"));
-        caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理"));
-        caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数"));
-    }
-
-    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
-    @GetMapping()
-    public AjaxResult getInfo() throws Exception
-    {
-        Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info());
-        Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats"));
-        Object dbSize = redisTemplate.execute((RedisCallback<Object>) connection -> connection.dbSize());
-
-        Map<String, Object> result = new HashMap<>(3);
-        result.put("info", info);
-        result.put("dbSize", dbSize);
-
-        List<Map<String, String>> pieList = new ArrayList<>();
-        commandStats.stringPropertyNames().forEach(key -> {
-            Map<String, String> data = new HashMap<>(2);
-            String property = commandStats.getProperty(key);
-            data.put("name", StringUtils.removeStart(key, "cmdstat_"));
-            data.put("value", StringUtils.substringBetween(property, "calls=", ",usec"));
-            pieList.add(data);
-        });
-        result.put("commandStats", pieList);
-        return AjaxResult.success(result);
-    }
-
-    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
-    @GetMapping("/getNames")
-    public AjaxResult cache()
-    {
-        return AjaxResult.success(caches);
-    }
-
-    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
-    @GetMapping("/getKeys/{cacheName}")
-    public AjaxResult getCacheKeys(@PathVariable String cacheName)
-    {
-        Set<String> cacheKeys = redisTemplate.keys(cacheName + "*");
-        return AjaxResult.success(new TreeSet<>(cacheKeys));
-    }
-
-    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
-    @GetMapping("/getValue/{cacheName}/{cacheKey}")
-    public AjaxResult getCacheValue(@PathVariable String cacheName, @PathVariable String cacheKey)
-    {
-        String cacheValue = redisTemplate.opsForValue().get(cacheKey);
-        SysCache sysCache = new SysCache(cacheName, cacheKey, cacheValue);
-        return AjaxResult.success(sysCache);
-    }
-
-    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
-    @DeleteMapping("/clearCacheName/{cacheName}")
-    public AjaxResult clearCacheName(@PathVariable String cacheName)
-    {
-        Collection<String> cacheKeys = redisTemplate.keys(cacheName + "*");
-        redisTemplate.delete(cacheKeys);
-        return AjaxResult.success();
-    }
-
-    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
-    @DeleteMapping("/clearCacheKey/{cacheKey}")
-    public AjaxResult clearCacheKey(@PathVariable String cacheKey)
-    {
-        redisTemplate.delete(cacheKey);
-        return AjaxResult.success();
-    }
-
-    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
-    @DeleteMapping("/clearCacheAll")
-    public AjaxResult clearCacheAll()
-    {
-        Collection<String> cacheKeys = redisTemplate.keys("*");
-        redisTemplate.delete(cacheKeys);
-        return AjaxResult.success();
-    }
-}
+//package com.cn.fdapfe.web.controller.monitor;
+//
+//import java.util.ArrayList;
+//import java.util.Collection;
+//import java.util.HashMap;
+//import java.util.List;
+//import java.util.Map;
+//import java.util.Properties;
+//import java.util.Set;
+//import java.util.TreeSet;
+//
+//import com.cn.fdapfe.common.core.redis.CaffeineCache;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.security.access.prepost.PreAuthorize;
+//import org.springframework.web.bind.annotation.DeleteMapping;
+//import org.springframework.web.bind.annotation.GetMapping;
+//import org.springframework.web.bind.annotation.PathVariable;
+//import org.springframework.web.bind.annotation.RequestMapping;
+//import org.springframework.web.bind.annotation.RestController;
+//import com.cn.fdapfe.common.constant.CacheConstants;
+//import com.cn.fdapfe.common.core.domain.AjaxResult;
+//import com.cn.fdapfe.common.utils.StringUtils;
+//import com.cn.fdapfe.system.domain.SysCache;
+//
+///**
+// * 缓存监控
+// *
+// * @author ruoyi
+// */
+//@RestController
+//@RequestMapping("/monitor/cache")
+//public class CacheController
+//{
+//    @Autowired
+//    private CaffeineCache caffeineCache;
+//
+//    private final static List<SysCache> caches = new ArrayList<SysCache>();
+//    {
+//        caches.add(new SysCache(CacheConstants.LOGIN_TOKEN_KEY, "用户信息"));
+//        caches.add(new SysCache(CacheConstants.SYS_CONFIG_KEY, "配置信息"));
+//        caches.add(new SysCache(CacheConstants.SYS_DICT_KEY, "数据字典"));
+//        caches.add(new SysCache(CacheConstants.CAPTCHA_CODE_KEY, "验证码"));
+//        caches.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "防重提交"));
+//        caches.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理"));
+//        caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数"));
+//    }
+//
+//    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+//    @GetMapping()
+//    public AjaxResult getInfo() throws Exception
+//    {
+//        Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info());
+//        Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats"));
+//        Object dbSize = redisTemplate.execute((RedisCallback<Object>) connection -> connection.dbSize());
+//
+//        Map<String, Object> result = new HashMap<>(3);
+//        result.put("info", info);
+//        result.put("dbSize", dbSize);
+//
+//        List<Map<String, String>> pieList = new ArrayList<>();
+//        commandStats.stringPropertyNames().forEach(key -> {
+//            Map<String, String> data = new HashMap<>(2);
+//            String property = commandStats.getProperty(key);
+//            data.put("name", StringUtils.removeStart(key, "cmdstat_"));
+//            data.put("value", StringUtils.substringBetween(property, "calls=", ",usec"));
+//            pieList.add(data);
+//        });
+//        result.put("commandStats", pieList);
+//        return AjaxResult.success(result);
+//    }
+//
+//    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+//    @GetMapping("/getNames")
+//    public AjaxResult cache()
+//    {
+//        return AjaxResult.success(caches);
+//    }
+//
+//    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+//    @GetMapping("/getKeys/{cacheName}")
+//    public AjaxResult getCacheKeys(@PathVariable String cacheName)
+//    {
+//        Set<String> cacheKeys = redisTemplate.keys(cacheName + "*");
+//        return AjaxResult.success(new TreeSet<>(cacheKeys));
+//    }
+//
+//    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+//    @GetMapping("/getValue/{cacheName}/{cacheKey}")
+//    public AjaxResult getCacheValue(@PathVariable String cacheName, @PathVariable String cacheKey)
+//    {
+//        String cacheValue = redisTemplate.opsForValue().get(cacheKey);
+//        SysCache sysCache = new SysCache(cacheName, cacheKey, cacheValue);
+//        return AjaxResult.success(sysCache);
+//    }
+//
+//    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+//    @DeleteMapping("/clearCacheName/{cacheName}")
+//    public AjaxResult clearCacheName(@PathVariable String cacheName)
+//    {
+//        Collection<String> cacheKeys = redisTemplate.keys(cacheName + "*");
+//        redisTemplate.delete(cacheKeys);
+//        return AjaxResult.success();
+//    }
+//
+//    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+//    @DeleteMapping("/clearCacheKey/{cacheKey}")
+//    public AjaxResult clearCacheKey(@PathVariable String cacheKey)
+//    {
+//        redisTemplate.delete(cacheKey);
+//        return AjaxResult.success();
+//    }
+//
+//    @PreAuthorize("@ss.hasPermi('monitor:cache:list')")
+//    @DeleteMapping("/clearCacheAll")
+//    public AjaxResult clearCacheAll()
+//    {
+//        Collection<String> cacheKeys = redisTemplate.keys("*");
+//        redisTemplate.delete(cacheKeys);
+//        return AjaxResult.success();
+//    }
+//}

+ 6 - 5
fdapfe-admin/src/main/java/com/cn/fdapfe/web/controller/monitor/SysUserOnlineController.java

@@ -4,6 +4,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+
+import com.cn.fdapfe.common.core.redis.CaffeineCache;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -17,7 +19,6 @@ import com.cn.fdapfe.common.core.controller.BaseController;
 import com.cn.fdapfe.common.core.domain.AjaxResult;
 import com.cn.fdapfe.common.core.domain.model.LoginUser;
 import com.cn.fdapfe.common.core.page.TableDataInfo;
-import com.cn.fdapfe.common.core.redis.RedisCache;
 import com.cn.fdapfe.common.enums.BusinessType;
 import com.cn.fdapfe.common.utils.StringUtils;
 import com.cn.fdapfe.system.domain.SysUserOnline;
@@ -36,17 +37,17 @@ public class SysUserOnlineController extends BaseController
     private ISysUserOnlineService userOnlineService;
 
     @Autowired
-    private RedisCache redisCache;
+    private CaffeineCache caffeineCache;
 
     @PreAuthorize("@ss.hasPermi('monitor:online:list')")
     @GetMapping("/list")
     public TableDataInfo list(String ipaddr, String userName)
     {
-        Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
+        Collection<String> keys = caffeineCache.findKeysByPattern(CacheConstants.LOGIN_TOKEN_KEY + "*");
         List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
         for (String key : keys)
         {
-            LoginUser user = redisCache.getCacheObject(key);
+            LoginUser user = (LoginUser) caffeineCache.getCache(key);
             if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName))
             {
                 userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
@@ -77,7 +78,7 @@ public class SysUserOnlineController extends BaseController
     @DeleteMapping("/{tokenId}")
     public AjaxResult forceLogout(@PathVariable String tokenId)
     {
-        redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId);
+        caffeineCache.deleteCacheByKey(CacheConstants.LOGIN_TOKEN_KEY + tokenId);
         return success();
     }
 }

+ 2 - 2
fdapfe-admin/src/main/resources/application-druid.yml

@@ -6,9 +6,9 @@ spring:
         druid:
             # 主库数据源
             master:
-                url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+                url: jdbc:mysql://101.126.133.7:9006/fdapfe?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                 username: root
-                password: password
+                password: 404cf3eae29df38f
             # 从库数据源
             slave:
                 # 从数据源开关/默认关闭

+ 26 - 23
fdapfe-admin/src/main/resources/application.yml

@@ -65,29 +65,32 @@ spring:
     restart:
       # 热部署开关
       enabled: true
-  # redis 配置
-  redis:
-    # 地址
-    host: localhost
-    # 端口,默认为6379
-    port: 6379
-    # 数据库索引
-    database: 0
-    # 密码
-    password:
-    # 连接超时时间
-    timeout: 10s
-    lettuce:
-      pool:
-        # 连接池中的最小空闲连接
-        min-idle: 0
-        # 连接池中的最大空闲连接
-        max-idle: 8
-        # 连接池的最大数据库连接数
-        max-active: 8
-        # #连接池最大阻塞等待时间(使用负值表示没有限制)
-        max-wait: -1ms
-
+  # redis 配置 替换为caffeine缓存
+#  redis:
+#    # 地址
+#    host: localhost
+#    # 端口,默认为6379
+#    port: 6379
+#    # 数据库索引
+#    database: 0
+#    # 密码
+#    password:
+#    # 连接超时时间
+#    timeout: 10s
+#    lettuce:
+#      pool:
+#        # 连接池中的最小空闲连接
+#        min-idle: 0
+#        # 连接池中的最大空闲连接
+#        max-idle: 8
+#        # 连接池的最大数据库连接数
+#        max-active: 8
+#        # #连接池最大阻塞等待时间(使用负值表示没有限制)
+#        max-wait: -1ms
+  cache:
+    type: caffeine
+    caffeine:
+      spec: maximumSize=1000,expireAfterAccess=60m
 # token配置
 token:
   # 令牌自定义标识

+ 8 - 3
fdapfe-common/pom.xml

@@ -96,9 +96,14 @@
         </dependency>
 
         <!-- redis 缓存操作 -->
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-data-redis</artifactId>
+<!--        <dependency>-->
+<!--            <groupId>org.springframework.boot</groupId>-->
+<!--            <artifactId>spring-boot-starter-data-redis</artifactId>-->
+<!--        </dependency>-->
+        <!-- 替换为caffeine 缓存操作 -->
+        <dependency>
+            <groupId>com.github.ben-manes.caffeine</groupId>
+            <artifactId>caffeine</artifactId>
         </dependency>
 
         <!-- pool 对象池 -->

+ 123 - 0
fdapfe-common/src/main/java/com/cn/fdapfe/common/core/redis/CaffeineCache.java

@@ -0,0 +1,123 @@
+package com.cn.fdapfe.common.core.redis;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@Component
+public class CaffeineCache {
+    @Autowired
+    private Cache<String, Object> caffeineCacheCustomize;
+
+    public void setCache(String key, Object value) {
+        caffeineCacheCustomize.put(key, value);
+    }
+
+    /**
+     * 动态设置缓存项的过期时间
+     *
+     * @param key   缓存键
+     * @param value 缓存值
+     * @param time  过期时间
+     * @param unit  时间单位
+     */
+    public void setCacheWithExpiration(String key, Object value, long time, TimeUnit unit) {
+        caffeineCacheCustomize.policy().expireAfterWrite()
+                .ifPresent(policy -> policy.setExpiresAfter(time, unit));
+        caffeineCacheCustomize.put(key, value);
+    }
+
+    public Object getCache(String key) {
+        return caffeineCacheCustomize.getIfPresent(key);
+    }
+
+    /**
+     * 删除指定 key 的缓存项
+     */
+    public void deleteCacheByKey(String key) {
+        caffeineCacheCustomize.invalidate(key);
+    }
+
+    /**
+     * 批量删除缓存项
+     */
+    public void deleteCacheByKeys(Set<String> keys) {
+        caffeineCacheCustomize.invalidateAll(keys);
+    }
+
+    /**
+     * 清空整个缓存
+     */
+    public void clearAllCache() {
+        caffeineCacheCustomize.invalidateAll();
+    }
+
+    /**
+     * 根据条件删除缓存项
+     */
+    public void deleteCacheByCondition() {
+        Map<String, Object> cacheMap = caffeineCacheCustomize.asMap();
+        cacheMap.entrySet().removeIf(entry -> {
+            String key = entry.getKey();
+            Object value = entry.getValue();
+            // 自定义删除条件
+            return key.startsWith("temp_") || value == null;
+        });
+    }
+
+
+    /**
+     * 按通配符删除缓存项
+     *
+     * @param pattern 通配符模式,例如 "user_*"
+     */
+    public void deleteCacheByPattern(String pattern) {
+        Map<String, Object> cacheMap = caffeineCacheCustomize.asMap();
+        cacheMap.keySet().removeIf(key -> key.matches(convertPatternToRegex(pattern)));
+    }
+    /**
+     * 按通配符查找匹配的缓存键
+     *
+     * @param pattern 通配符模式,例如 "user_*"
+     * @return 匹配的缓存键列表
+     */
+    public List<String> findKeysByPattern(String pattern) {
+        List<String> matchedKeys = new ArrayList<>();
+        Map<String, Object> cacheMap = caffeineCacheCustomize.asMap();
+        String regex = convertPatternToRegex(pattern);
+
+        for (String key : cacheMap.keySet()) {
+            if (key.matches(regex)) {
+                matchedKeys.add(key);
+            }
+        }
+
+        return matchedKeys;
+    }
+
+    /**
+     * 将通配符模式转换为正则表达式
+     *
+     * @param pattern 通配符模式,例如 "user_*"
+     * @return 正则表达式
+     */
+    private String convertPatternToRegex(String pattern) {
+        return pattern.replace("*", ".*");
+    }
+
+    /**
+     * 检查 key 是否存在
+     *
+     * @param key       缓存键
+     * @return 是否存在
+     */
+    public boolean isKeyExists(String key) {
+        return caffeineCacheCustomize.getIfPresent(key) != null;
+    }
+}

+ 268 - 268
fdapfe-common/src/main/java/com/cn/fdapfe/common/core/redis/RedisCache.java

@@ -1,268 +1,268 @@
-package com.cn.fdapfe.common.core.redis;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.BoundSetOperations;
-import org.springframework.data.redis.core.HashOperations;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.core.ValueOperations;
-import org.springframework.stereotype.Component;
-
-/**
- * spring redis 工具类
- *
- * @author ruoyi
- **/
-@SuppressWarnings(value = { "unchecked", "rawtypes" })
-@Component
-public class RedisCache
-{
-    @Autowired
-    public RedisTemplate redisTemplate;
-
-    /**
-     * 缓存基本的对象,Integer、String、实体类等
-     *
-     * @param key 缓存的键值
-     * @param value 缓存的值
-     */
-    public <T> void setCacheObject(final String key, final T value)
-    {
-        redisTemplate.opsForValue().set(key, value);
-    }
-
-    /**
-     * 缓存基本的对象,Integer、String、实体类等
-     *
-     * @param key 缓存的键值
-     * @param value 缓存的值
-     * @param timeout 时间
-     * @param timeUnit 时间颗粒度
-     */
-    public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit)
-    {
-        redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
-    }
-
-    /**
-     * 设置有效时间
-     *
-     * @param key Redis键
-     * @param timeout 超时时间
-     * @return true=设置成功;false=设置失败
-     */
-    public boolean expire(final String key, final long timeout)
-    {
-        return expire(key, timeout, TimeUnit.SECONDS);
-    }
-
-    /**
-     * 设置有效时间
-     *
-     * @param key Redis键
-     * @param timeout 超时时间
-     * @param unit 时间单位
-     * @return true=设置成功;false=设置失败
-     */
-    public boolean expire(final String key, final long timeout, final TimeUnit unit)
-    {
-        return redisTemplate.expire(key, timeout, unit);
-    }
-
-    /**
-     * 获取有效时间
-     *
-     * @param key Redis键
-     * @return 有效时间
-     */
-    public long getExpire(final String key)
-    {
-        return redisTemplate.getExpire(key);
-    }
-
-    /**
-     * 判断 key是否存在
-     *
-     * @param key 键
-     * @return true 存在 false不存在
-     */
-    public Boolean hasKey(String key)
-    {
-        return redisTemplate.hasKey(key);
-    }
-
-    /**
-     * 获得缓存的基本对象。
-     *
-     * @param key 缓存键值
-     * @return 缓存键值对应的数据
-     */
-    public <T> T getCacheObject(final String key)
-    {
-        ValueOperations<String, T> operation = redisTemplate.opsForValue();
-        return operation.get(key);
-    }
-
-    /**
-     * 删除单个对象
-     *
-     * @param key
-     */
-    public boolean deleteObject(final String key)
-    {
-        return redisTemplate.delete(key);
-    }
-
-    /**
-     * 删除集合对象
-     *
-     * @param collection 多个对象
-     * @return
-     */
-    public boolean deleteObject(final Collection collection)
-    {
-        return redisTemplate.delete(collection) > 0;
-    }
-
-    /**
-     * 缓存List数据
-     *
-     * @param key 缓存的键值
-     * @param dataList 待缓存的List数据
-     * @return 缓存的对象
-     */
-    public <T> long setCacheList(final String key, final List<T> dataList)
-    {
-        Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
-        return count == null ? 0 : count;
-    }
-
-    /**
-     * 获得缓存的list对象
-     *
-     * @param key 缓存的键值
-     * @return 缓存键值对应的数据
-     */
-    public <T> List<T> getCacheList(final String key)
-    {
-        return redisTemplate.opsForList().range(key, 0, -1);
-    }
-
-    /**
-     * 缓存Set
-     *
-     * @param key 缓存键值
-     * @param dataSet 缓存的数据
-     * @return 缓存数据的对象
-     */
-    public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet)
-    {
-        BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
-        Iterator<T> it = dataSet.iterator();
-        while (it.hasNext())
-        {
-            setOperation.add(it.next());
-        }
-        return setOperation;
-    }
-
-    /**
-     * 获得缓存的set
-     *
-     * @param key
-     * @return
-     */
-    public <T> Set<T> getCacheSet(final String key)
-    {
-        return redisTemplate.opsForSet().members(key);
-    }
-
-    /**
-     * 缓存Map
-     *
-     * @param key
-     * @param dataMap
-     */
-    public <T> void setCacheMap(final String key, final Map<String, T> dataMap)
-    {
-        if (dataMap != null) {
-            redisTemplate.opsForHash().putAll(key, dataMap);
-        }
-    }
-
-    /**
-     * 获得缓存的Map
-     *
-     * @param key
-     * @return
-     */
-    public <T> Map<String, T> getCacheMap(final String key)
-    {
-        return redisTemplate.opsForHash().entries(key);
-    }
-
-    /**
-     * 往Hash中存入数据
-     *
-     * @param key Redis键
-     * @param hKey Hash键
-     * @param value 值
-     */
-    public <T> void setCacheMapValue(final String key, final String hKey, final T value)
-    {
-        redisTemplate.opsForHash().put(key, hKey, value);
-    }
-
-    /**
-     * 获取Hash中的数据
-     *
-     * @param key Redis键
-     * @param hKey Hash键
-     * @return Hash中的对象
-     */
-    public <T> T getCacheMapValue(final String key, final String hKey)
-    {
-        HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
-        return opsForHash.get(key, hKey);
-    }
-
-    /**
-     * 获取多个Hash中的数据
-     *
-     * @param key Redis键
-     * @param hKeys Hash键集合
-     * @return Hash对象集合
-     */
-    public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys)
-    {
-        return redisTemplate.opsForHash().multiGet(key, hKeys);
-    }
-
-    /**
-     * 删除Hash中的某条数据
-     *
-     * @param key Redis键
-     * @param hKey Hash键
-     * @return 是否成功
-     */
-    public boolean deleteCacheMapValue(final String key, final String hKey)
-    {
-        return redisTemplate.opsForHash().delete(key, hKey) > 0;
-    }
-
-    /**
-     * 获得缓存的基本对象列表
-     *
-     * @param pattern 字符串前缀
-     * @return 对象列表
-     */
-    public Collection<String> keys(final String pattern)
-    {
-        return redisTemplate.keys(pattern);
-    }
-}
+//package com.cn.fdapfe.common.core.redis;
+//
+//import java.util.Collection;
+//import java.util.Iterator;
+//import java.util.List;
+//import java.util.Map;
+//import java.util.Set;
+//import java.util.concurrent.TimeUnit;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.data.redis.core.BoundSetOperations;
+//import org.springframework.data.redis.core.HashOperations;
+//import org.springframework.data.redis.core.RedisTemplate;
+//import org.springframework.data.redis.core.ValueOperations;
+//import org.springframework.stereotype.Component;
+//
+///**
+// * spring redis 工具类
+// *
+// * @author ruoyi
+// **/
+//@SuppressWarnings(value = { "unchecked", "rawtypes" })
+//@Component
+//public class RedisCache
+//{
+//    @Autowired
+//    public RedisTemplate redisTemplate;
+//
+//    /**
+//     * 缓存基本的对象,Integer、String、实体类等
+//     *
+//     * @param key 缓存的键值
+//     * @param value 缓存的值
+//     */
+//    public <T> void setCacheObject(final String key, final T value)
+//    {
+//        redisTemplate.opsForValue().set(key, value);
+//    }
+//
+//    /**
+//     * 缓存基本的对象,Integer、String、实体类等
+//     *
+//     * @param key 缓存的键值
+//     * @param value 缓存的值
+//     * @param timeout 时间
+//     * @param timeUnit 时间颗粒度
+//     */
+//    public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit)
+//    {
+//        redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
+//    }
+//
+//    /**
+//     * 设置有效时间
+//     *
+//     * @param key Redis键
+//     * @param timeout 超时时间
+//     * @return true=设置成功;false=设置失败
+//     */
+//    public boolean expire(final String key, final long timeout)
+//    {
+//        return expire(key, timeout, TimeUnit.SECONDS);
+//    }
+//
+//    /**
+//     * 设置有效时间
+//     *
+//     * @param key Redis键
+//     * @param timeout 超时时间
+//     * @param unit 时间单位
+//     * @return true=设置成功;false=设置失败
+//     */
+//    public boolean expire(final String key, final long timeout, final TimeUnit unit)
+//    {
+//        return redisTemplate.expire(key, timeout, unit);
+//    }
+//
+//    /**
+//     * 获取有效时间
+//     *
+//     * @param key Redis键
+//     * @return 有效时间
+//     */
+//    public long getExpire(final String key)
+//    {
+//        return redisTemplate.getExpire(key);
+//    }
+//
+//    /**
+//     * 判断 key是否存在
+//     *
+//     * @param key 键
+//     * @return true 存在 false不存在
+//     */
+//    public Boolean hasKey(String key)
+//    {
+//        return redisTemplate.hasKey(key);
+//    }
+//
+//    /**
+//     * 获得缓存的基本对象。
+//     *
+//     * @param key 缓存键值
+//     * @return 缓存键值对应的数据
+//     */
+//    public <T> T getCacheObject(final String key)
+//    {
+//        ValueOperations<String, T> operation = redisTemplate.opsForValue();
+//        return operation.get(key);
+//    }
+//
+//    /**
+//     * 删除单个对象
+//     *
+//     * @param key
+//     */
+//    public boolean deleteObject(final String key)
+//    {
+//        return redisTemplate.delete(key);
+//    }
+//
+//    /**
+//     * 删除集合对象
+//     *
+//     * @param collection 多个对象
+//     * @return
+//     */
+//    public boolean deleteObject(final Collection collection)
+//    {
+//        return redisTemplate.delete(collection) > 0;
+//    }
+//
+//    /**
+//     * 缓存List数据
+//     *
+//     * @param key 缓存的键值
+//     * @param dataList 待缓存的List数据
+//     * @return 缓存的对象
+//     */
+//    public <T> long setCacheList(final String key, final List<T> dataList)
+//    {
+//        Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
+//        return count == null ? 0 : count;
+//    }
+//
+//    /**
+//     * 获得缓存的list对象
+//     *
+//     * @param key 缓存的键值
+//     * @return 缓存键值对应的数据
+//     */
+//    public <T> List<T> getCacheList(final String key)
+//    {
+//        return redisTemplate.opsForList().range(key, 0, -1);
+//    }
+//
+//    /**
+//     * 缓存Set
+//     *
+//     * @param key 缓存键值
+//     * @param dataSet 缓存的数据
+//     * @return 缓存数据的对象
+//     */
+//    public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet)
+//    {
+//        BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
+//        Iterator<T> it = dataSet.iterator();
+//        while (it.hasNext())
+//        {
+//            setOperation.add(it.next());
+//        }
+//        return setOperation;
+//    }
+//
+//    /**
+//     * 获得缓存的set
+//     *
+//     * @param key
+//     * @return
+//     */
+//    public <T> Set<T> getCacheSet(final String key)
+//    {
+//        return redisTemplate.opsForSet().members(key);
+//    }
+//
+//    /**
+//     * 缓存Map
+//     *
+//     * @param key
+//     * @param dataMap
+//     */
+//    public <T> void setCacheMap(final String key, final Map<String, T> dataMap)
+//    {
+//        if (dataMap != null) {
+//            redisTemplate.opsForHash().putAll(key, dataMap);
+//        }
+//    }
+//
+//    /**
+//     * 获得缓存的Map
+//     *
+//     * @param key
+//     * @return
+//     */
+//    public <T> Map<String, T> getCacheMap(final String key)
+//    {
+//        return redisTemplate.opsForHash().entries(key);
+//    }
+//
+//    /**
+//     * 往Hash中存入数据
+//     *
+//     * @param key Redis键
+//     * @param hKey Hash键
+//     * @param value 值
+//     */
+//    public <T> void setCacheMapValue(final String key, final String hKey, final T value)
+//    {
+//        redisTemplate.opsForHash().put(key, hKey, value);
+//    }
+//
+//    /**
+//     * 获取Hash中的数据
+//     *
+//     * @param key Redis键
+//     * @param hKey Hash键
+//     * @return Hash中的对象
+//     */
+//    public <T> T getCacheMapValue(final String key, final String hKey)
+//    {
+//        HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
+//        return opsForHash.get(key, hKey);
+//    }
+//
+//    /**
+//     * 获取多个Hash中的数据
+//     *
+//     * @param key Redis键
+//     * @param hKeys Hash键集合
+//     * @return Hash对象集合
+//     */
+//    public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys)
+//    {
+//        return redisTemplate.opsForHash().multiGet(key, hKeys);
+//    }
+//
+//    /**
+//     * 删除Hash中的某条数据
+//     *
+//     * @param key Redis键
+//     * @param hKey Hash键
+//     * @return 是否成功
+//     */
+//    public boolean deleteCacheMapValue(final String key, final String hKey)
+//    {
+//        return redisTemplate.opsForHash().delete(key, hKey) > 0;
+//    }
+//
+//    /**
+//     * 获得缓存的基本对象列表
+//     *
+//     * @param pattern 字符串前缀
+//     * @return 对象列表
+//     */
+//    public Collection<String> keys(final String pattern)
+//    {
+//        return redisTemplate.keys(pattern);
+//    }
+//}

+ 5 - 6
fdapfe-common/src/main/java/com/cn/fdapfe/common/utils/DictUtils.java

@@ -5,7 +5,7 @@ import java.util.List;
 import com.alibaba.fastjson2.JSONArray;
 import com.cn.fdapfe.common.constant.CacheConstants;
 import com.cn.fdapfe.common.core.domain.entity.SysDictData;
-import com.cn.fdapfe.common.core.redis.RedisCache;
+import com.cn.fdapfe.common.core.redis.CaffeineCache;
 import com.cn.fdapfe.common.utils.spring.SpringUtils;
 
 /**
@@ -28,7 +28,7 @@ public class DictUtils
      */
     public static void setDictCache(String key, List<SysDictData> dictDatas)
     {
-        SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), dictDatas);
+        SpringUtils.getBean(CaffeineCache.class).setCache(getCacheKey(key), dictDatas);
     }
 
     /**
@@ -39,7 +39,7 @@ public class DictUtils
      */
     public static List<SysDictData> getDictCache(String key)
     {
-        JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
+        JSONArray arrayCache = JSONArray.of(SpringUtils.getBean(CaffeineCache.class).getCache(getCacheKey(key)));
         if (StringUtils.isNotNull(arrayCache))
         {
             return arrayCache.toList(SysDictData.class);
@@ -214,7 +214,7 @@ public class DictUtils
      */
     public static void removeDictCache(String key)
     {
-        SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key));
+        SpringUtils.getBean(CaffeineCache.class).deleteCacheByKey(getCacheKey(key));
     }
 
     /**
@@ -222,8 +222,7 @@ public class DictUtils
      */
     public static void clearDictCache()
     {
-        Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_DICT_KEY + "*");
-        SpringUtils.getBean(RedisCache.class).deleteObject(keys);
+        SpringUtils.getBean(CaffeineCache.class).deleteCacheByPattern(CacheConstants.SYS_DICT_KEY + "*");
     }
 
     /**

+ 87 - 89
fdapfe-framework/src/main/java/com/cn/fdapfe/framework/aspectj/RateLimiterAspect.java

@@ -1,89 +1,87 @@
-package com.cn.fdapfe.framework.aspectj;
-
-import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.List;
-import org.aspectj.lang.JoinPoint;
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Before;
-import org.aspectj.lang.reflect.MethodSignature;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.core.script.RedisScript;
-import org.springframework.stereotype.Component;
-import com.cn.fdapfe.common.annotation.RateLimiter;
-import com.cn.fdapfe.common.enums.LimitType;
-import com.cn.fdapfe.common.exception.ServiceException;
-import com.cn.fdapfe.common.utils.StringUtils;
-import com.cn.fdapfe.common.utils.ip.IpUtils;
-
-/**
- * 限流处理
- *
- * @author ruoyi
- */
-@Aspect
-@Component
-public class RateLimiterAspect
-{
-    private static final Logger log = LoggerFactory.getLogger(RateLimiterAspect.class);
-
-    private RedisTemplate<Object, Object> redisTemplate;
-
-    private RedisScript<Long> limitScript;
-
-    @Autowired
-    public void setRedisTemplate1(RedisTemplate<Object, Object> redisTemplate)
-    {
-        this.redisTemplate = redisTemplate;
-    }
-
-    @Autowired
-    public void setLimitScript(RedisScript<Long> limitScript)
-    {
-        this.limitScript = limitScript;
-    }
-
-    @Before("@annotation(rateLimiter)")
-    public void doBefore(JoinPoint point, RateLimiter rateLimiter) throws Throwable
-    {
-        int time = rateLimiter.time();
-        int count = rateLimiter.count();
-
-        String combineKey = getCombineKey(rateLimiter, point);
-        List<Object> keys = Collections.singletonList(combineKey);
-        try
-        {
-            Long number = redisTemplate.execute(limitScript, keys, count, time);
-            if (StringUtils.isNull(number) || number.intValue() > count)
-            {
-                throw new ServiceException("访问过于频繁,请稍候再试");
-            }
-            log.info("限制请求'{}',当前请求'{}',缓存key'{}'", count, number.intValue(), combineKey);
-        }
-        catch (ServiceException e)
-        {
-            throw e;
-        }
-        catch (Exception e)
-        {
-            throw new RuntimeException("服务器限流异常,请稍候再试");
-        }
-    }
-
-    public String getCombineKey(RateLimiter rateLimiter, JoinPoint point)
-    {
-        StringBuffer stringBuffer = new StringBuffer(rateLimiter.key());
-        if (rateLimiter.limitType() == LimitType.IP)
-        {
-            stringBuffer.append(IpUtils.getIpAddr()).append("-");
-        }
-        MethodSignature signature = (MethodSignature) point.getSignature();
-        Method method = signature.getMethod();
-        Class<?> targetClass = method.getDeclaringClass();
-        stringBuffer.append(targetClass.getName()).append("-").append(method.getName());
-        return stringBuffer.toString();
-    }
-}
+//package com.cn.fdapfe.framework.aspectj;
+//
+//import java.lang.reflect.Method;
+//import java.util.Collections;
+//import java.util.List;
+//import org.aspectj.lang.JoinPoint;
+//import org.aspectj.lang.annotation.Aspect;
+//import org.aspectj.lang.annotation.Before;
+//import org.aspectj.lang.reflect.MethodSignature;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.stereotype.Component;
+//import com.cn.fdapfe.common.annotation.RateLimiter;
+//import com.cn.fdapfe.common.enums.LimitType;
+//import com.cn.fdapfe.common.exception.ServiceException;
+//import com.cn.fdapfe.common.utils.StringUtils;
+//import com.cn.fdapfe.common.utils.ip.IpUtils;
+//
+///**
+// * 限流处理
+// *
+// * @author ruoyi
+// */
+//@Aspect
+//@Component
+//public class RateLimiterAspect
+//{
+//    private static final Logger log = LoggerFactory.getLogger(RateLimiterAspect.class);
+//
+//    private RedisTemplate<Object, Object> redisTemplate;
+//
+//    private RedisScript<Long> limitScript;
+//
+//    @Autowired
+//    public void setRedisTemplate1(RedisTemplate<Object, Object> redisTemplate)
+//    {
+//        this.redisTemplate = redisTemplate;
+//    }
+//
+//    @Autowired
+//    public void setLimitScript(RedisScript<Long> limitScript)
+//    {
+//        this.limitScript = limitScript;
+//    }
+//
+//    @Before("@annotation(rateLimiter)")
+//    public void doBefore(JoinPoint point, RateLimiter rateLimiter) throws Throwable
+//    {
+//        int time = rateLimiter.time();
+//        int count = rateLimiter.count();
+//
+//        String combineKey = getCombineKey(rateLimiter, point);
+//        List<Object> keys = Collections.singletonList(combineKey);
+//        try
+//        {
+//            Long number = redisTemplate.execute(limitScript, keys, count, time);
+//            if (StringUtils.isNull(number) || number.intValue() > count)
+//            {
+//                throw new ServiceException("访问过于频繁,请稍候再试");
+//            }
+//            log.info("限制请求'{}',当前请求'{}',缓存key'{}'", count, number.intValue(), combineKey);
+//        }
+//        catch (ServiceException e)
+//        {
+//            throw e;
+//        }
+//        catch (Exception e)
+//        {
+//            throw new RuntimeException("服务器限流异常,请稍候再试");
+//        }
+//    }
+//
+//    public String getCombineKey(RateLimiter rateLimiter, JoinPoint point)
+//    {
+//        StringBuffer stringBuffer = new StringBuffer(rateLimiter.key());
+//        if (rateLimiter.limitType() == LimitType.IP)
+//        {
+//            stringBuffer.append(IpUtils.getIpAddr()).append("-");
+//        }
+//        MethodSignature signature = (MethodSignature) point.getSignature();
+//        Method method = signature.getMethod();
+//        Class<?> targetClass = method.getDeclaringClass();
+//        stringBuffer.append(targetClass.getName()).append("-").append(method.getName());
+//        return stringBuffer.toString();
+//    }
+//}

+ 23 - 0
fdapfe-framework/src/main/java/com/cn/fdapfe/framework/config/CaffeineConfig.java

@@ -0,0 +1,23 @@
+package com.cn.fdapfe.framework.config;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.caffeine.CaffeineCacheManager;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+
+import java.util.concurrent.TimeUnit;
+
+@Configuration
+public class CaffeineConfig {
+    @Bean
+    @Primary
+    public Cache<String, Object> caffeineCacheCustomize() {
+        return Caffeine.newBuilder()
+                .expireAfterWrite(60, TimeUnit.MINUTES) // 缓存过期时间
+                .maximumSize(1000) // 缓存最大容量
+                .build();
+    }
+}

+ 52 - 52
fdapfe-framework/src/main/java/com/cn/fdapfe/framework/config/FastJson2JsonRedisSerializer.java

@@ -1,52 +1,52 @@
-package com.cn.fdapfe.framework.config;
-
-import java.nio.charset.Charset;
-import org.springframework.data.redis.serializer.RedisSerializer;
-import org.springframework.data.redis.serializer.SerializationException;
-import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONReader;
-import com.alibaba.fastjson2.JSONWriter;
-import com.alibaba.fastjson2.filter.Filter;
-import com.cn.fdapfe.common.constant.Constants;
-
-/**
- * Redis使用FastJson序列化
- * 
- * @author ruoyi
- */
-public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
-{
-    public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
-
-    static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter(Constants.JSON_WHITELIST_STR);
-
-    private Class<T> clazz;
-
-    public FastJson2JsonRedisSerializer(Class<T> clazz)
-    {
-        super();
-        this.clazz = clazz;
-    }
-
-    @Override
-    public byte[] serialize(T t) throws SerializationException
-    {
-        if (t == null)
-        {
-            return new byte[0];
-        }
-        return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
-    }
-
-    @Override
-    public T deserialize(byte[] bytes) throws SerializationException
-    {
-        if (bytes == null || bytes.length <= 0)
-        {
-            return null;
-        }
-        String str = new String(bytes, DEFAULT_CHARSET);
-
-        return JSON.parseObject(str, clazz, AUTO_TYPE_FILTER);
-    }
-}
+//package com.cn.fdapfe.framework.config;
+//
+//import java.nio.charset.Charset;
+//import org.springframework.data.redis.serializer.RedisSerializer;
+//import org.springframework.data.redis.serializer.SerializationException;
+//import com.alibaba.fastjson2.JSON;
+//import com.alibaba.fastjson2.JSONReader;
+//import com.alibaba.fastjson2.JSONWriter;
+//import com.alibaba.fastjson2.filter.Filter;
+//import com.cn.fdapfe.common.constant.Constants;
+//
+///**
+// * Redis使用FastJson序列化
+// *
+// * @author ruoyi
+// */
+//public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
+//{
+//    public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
+//
+//    static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter(Constants.JSON_WHITELIST_STR);
+//
+//    private Class<T> clazz;
+//
+//    public FastJson2JsonRedisSerializer(Class<T> clazz)
+//    {
+//        super();
+//        this.clazz = clazz;
+//    }
+//
+//    @Override
+//    public byte[] serialize(T t) throws SerializationException
+//    {
+//        if (t == null)
+//        {
+//            return new byte[0];
+//        }
+//        return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
+//    }
+//
+//    @Override
+//    public T deserialize(byte[] bytes) throws SerializationException
+//    {
+//        if (bytes == null || bytes.length <= 0)
+//        {
+//            return null;
+//        }
+//        String str = new String(bytes, DEFAULT_CHARSET);
+//
+//        return JSON.parseObject(str, clazz, AUTO_TYPE_FILTER);
+//    }
+//}

+ 69 - 69
fdapfe-framework/src/main/java/com/cn/fdapfe/framework/config/RedisConfig.java

@@ -1,69 +1,69 @@
-package com.cn.fdapfe.framework.config;
-
-import org.springframework.cache.annotation.CachingConfigurerSupport;
-import org.springframework.cache.annotation.EnableCaching;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.core.script.DefaultRedisScript;
-import org.springframework.data.redis.serializer.StringRedisSerializer;
-
-/**
- * redis配置
- * 
- * @author ruoyi
- */
-@Configuration
-@EnableCaching
-public class RedisConfig extends CachingConfigurerSupport
-{
-    @Bean
-    @SuppressWarnings(value = { "unchecked", "rawtypes" })
-    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory)
-    {
-        RedisTemplate<Object, Object> template = new RedisTemplate<>();
-        template.setConnectionFactory(connectionFactory);
-
-        FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
-
-        // 使用StringRedisSerializer来序列化和反序列化redis的key值
-        template.setKeySerializer(new StringRedisSerializer());
-        template.setValueSerializer(serializer);
-
-        // Hash的key也采用StringRedisSerializer的序列化方式
-        template.setHashKeySerializer(new StringRedisSerializer());
-        template.setHashValueSerializer(serializer);
-
-        template.afterPropertiesSet();
-        return template;
-    }
-
-    @Bean
-    public DefaultRedisScript<Long> limitScript()
-    {
-        DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
-        redisScript.setScriptText(limitScriptText());
-        redisScript.setResultType(Long.class);
-        return redisScript;
-    }
-
-    /**
-     * 限流脚本
-     */
-    private String limitScriptText()
-    {
-        return "local key = KEYS[1]\n" +
-                "local count = tonumber(ARGV[1])\n" +
-                "local time = tonumber(ARGV[2])\n" +
-                "local current = redis.call('get', key);\n" +
-                "if current and tonumber(current) > count then\n" +
-                "    return tonumber(current);\n" +
-                "end\n" +
-                "current = redis.call('incr', key)\n" +
-                "if tonumber(current) == 1 then\n" +
-                "    redis.call('expire', key, time)\n" +
-                "end\n" +
-                "return tonumber(current);";
-    }
-}
+//package com.cn.fdapfe.framework.config;
+//
+//import org.springframework.cache.annotation.CachingConfigurerSupport;
+//import org.springframework.cache.annotation.EnableCaching;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.data.redis.connection.RedisConnectionFactory;
+//import org.springframework.data.redis.core.RedisTemplate;
+//import org.springframework.data.redis.core.script.DefaultRedisScript;
+//import org.springframework.data.redis.serializer.StringRedisSerializer;
+//
+///**
+// * redis配置
+// *
+// * @author ruoyi
+// */
+//@Configuration
+//@EnableCaching
+//public class RedisConfig extends CachingConfigurerSupport
+//{
+//    @Bean
+//    @SuppressWarnings(value = { "unchecked", "rawtypes" })
+//    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory)
+//    {
+//        RedisTemplate<Object, Object> template = new RedisTemplate<>();
+//        template.setConnectionFactory(connectionFactory);
+//
+//        FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
+//
+//        // 使用StringRedisSerializer来序列化和反序列化redis的key值
+//        template.setKeySerializer(new StringRedisSerializer());
+//        template.setValueSerializer(serializer);
+//
+//        // Hash的key也采用StringRedisSerializer的序列化方式
+//        template.setHashKeySerializer(new StringRedisSerializer());
+//        template.setHashValueSerializer(serializer);
+//
+//        template.afterPropertiesSet();
+//        return template;
+//    }
+//
+//    @Bean
+//    public DefaultRedisScript<Long> limitScript()
+//    {
+//        DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
+//        redisScript.setScriptText(limitScriptText());
+//        redisScript.setResultType(Long.class);
+//        return redisScript;
+//    }
+//
+//    /**
+//     * 限流脚本
+//     */
+//    private String limitScriptText()
+//    {
+//        return "local key = KEYS[1]\n" +
+//                "local count = tonumber(ARGV[1])\n" +
+//                "local time = tonumber(ARGV[2])\n" +
+//                "local current = redis.call('get', key);\n" +
+//                "if current and tonumber(current) > count then\n" +
+//                "    return tonumber(current);\n" +
+//                "end\n" +
+//                "current = redis.call('incr', key)\n" +
+//                "if tonumber(current) == 1 then\n" +
+//                "    redis.call('expire', key, time)\n" +
+//                "end\n" +
+//                "return tonumber(current);";
+//    }
+//}

+ 5 - 4
fdapfe-framework/src/main/java/com/cn/fdapfe/framework/interceptor/impl/SameUrlDataInterceptor.java

@@ -4,13 +4,14 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import javax.servlet.http.HttpServletRequest;
+
+import com.cn.fdapfe.common.core.redis.CaffeineCache;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 import com.alibaba.fastjson2.JSON;
 import com.cn.fdapfe.common.annotation.RepeatSubmit;
 import com.cn.fdapfe.common.constant.CacheConstants;
-import com.cn.fdapfe.common.core.redis.RedisCache;
 import com.cn.fdapfe.common.filter.RepeatedlyRequestWrapper;
 import com.cn.fdapfe.common.utils.StringUtils;
 import com.cn.fdapfe.common.utils.http.HttpHelper;
@@ -34,7 +35,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
     private String header;
 
     @Autowired
-    private RedisCache redisCache;
+    private CaffeineCache caffeineCache;
 
     @SuppressWarnings("unchecked")
     @Override
@@ -65,7 +66,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
         // 唯一标识(指定key + url + 消息头)
         String cacheRepeatKey = CacheConstants.REPEAT_SUBMIT_KEY + url + submitKey;
 
-        Object sessionObj = redisCache.getCacheObject(cacheRepeatKey);
+        Object sessionObj = caffeineCache.getCache(cacheRepeatKey);
         if (sessionObj != null)
         {
             Map<String, Object> sessionMap = (Map<String, Object>) sessionObj;
@@ -80,7 +81,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
         }
         Map<String, Object> cacheMap = new HashMap<String, Object>();
         cacheMap.put(url, nowDataMap);
-        redisCache.setCacheObject(cacheRepeatKey, cacheMap, annotation.interval(), TimeUnit.MILLISECONDS);
+        caffeineCache.setCacheWithExpiration(cacheRepeatKey, cacheMap, annotation.interval(), TimeUnit.MILLISECONDS);
         return false;
     }
 

+ 13 - 16
fdapfe-framework/src/main/java/com/cn/fdapfe/framework/web/service/SysLoginService.java

@@ -1,24 +1,13 @@
 package com.cn.fdapfe.framework.web.service;
 
-import javax.annotation.Resource;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.authentication.BadCredentialsException;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.Authentication;
-import org.springframework.stereotype.Component;
 import com.cn.fdapfe.common.constant.CacheConstants;
 import com.cn.fdapfe.common.constant.Constants;
 import com.cn.fdapfe.common.constant.UserConstants;
 import com.cn.fdapfe.common.core.domain.entity.SysUser;
 import com.cn.fdapfe.common.core.domain.model.LoginUser;
-import com.cn.fdapfe.common.core.redis.RedisCache;
+import com.cn.fdapfe.common.core.redis.CaffeineCache;
 import com.cn.fdapfe.common.exception.ServiceException;
-import com.cn.fdapfe.common.exception.user.BlackListException;
-import com.cn.fdapfe.common.exception.user.CaptchaException;
-import com.cn.fdapfe.common.exception.user.CaptchaExpireException;
-import com.cn.fdapfe.common.exception.user.UserNotExistsException;
-import com.cn.fdapfe.common.exception.user.UserPasswordNotMatchException;
+import com.cn.fdapfe.common.exception.user.*;
 import com.cn.fdapfe.common.utils.DateUtils;
 import com.cn.fdapfe.common.utils.MessageUtils;
 import com.cn.fdapfe.common.utils.StringUtils;
@@ -28,6 +17,14 @@ import com.cn.fdapfe.framework.manager.factory.AsyncFactory;
 import com.cn.fdapfe.framework.security.context.AuthenticationContextHolder;
 import com.cn.fdapfe.system.service.ISysConfigService;
 import com.cn.fdapfe.system.service.ISysUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
 
 /**
  * 登录校验方法
@@ -44,7 +41,7 @@ public class SysLoginService
     private AuthenticationManager authenticationManager;
 
     @Autowired
-    private RedisCache redisCache;
+    private CaffeineCache caffeineCache;
     
     @Autowired
     private ISysUserService userService;
@@ -114,13 +111,13 @@ public class SysLoginService
         if (captchaEnabled)
         {
             String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
-            String captcha = redisCache.getCacheObject(verifyKey);
+            String captcha = (String) caffeineCache.getCache(verifyKey);
             if (captcha == null)
             {
                 AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
                 throw new CaptchaExpireException();
             }
-            redisCache.deleteObject(verifyKey);
+            caffeineCache.deleteCacheByKey(verifyKey);
             if (!code.equalsIgnoreCase(captcha))
             {
                 AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));

+ 12 - 11
fdapfe-framework/src/main/java/com/cn/fdapfe/framework/web/service/SysPasswordService.java

@@ -1,17 +1,18 @@
 package com.cn.fdapfe.framework.web.service;
 
-import java.util.concurrent.TimeUnit;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.security.core.Authentication;
-import org.springframework.stereotype.Component;
 import com.cn.fdapfe.common.constant.CacheConstants;
 import com.cn.fdapfe.common.core.domain.entity.SysUser;
-import com.cn.fdapfe.common.core.redis.RedisCache;
+import com.cn.fdapfe.common.core.redis.CaffeineCache;
 import com.cn.fdapfe.common.exception.user.UserPasswordNotMatchException;
 import com.cn.fdapfe.common.exception.user.UserPasswordRetryLimitExceedException;
 import com.cn.fdapfe.common.utils.SecurityUtils;
 import com.cn.fdapfe.framework.security.context.AuthenticationContextHolder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Component;
+
+import java.util.concurrent.TimeUnit;
 
 /**
  * 登录密码方法
@@ -22,7 +23,7 @@ import com.cn.fdapfe.framework.security.context.AuthenticationContextHolder;
 public class SysPasswordService
 {
     @Autowired
-    private RedisCache redisCache;
+    private CaffeineCache caffeineCache;
 
     @Value(value = "${user.password.maxRetryCount}")
     private int maxRetryCount;
@@ -47,7 +48,7 @@ public class SysPasswordService
         String username = usernamePasswordAuthenticationToken.getName();
         String password = usernamePasswordAuthenticationToken.getCredentials().toString();
 
-        Integer retryCount = redisCache.getCacheObject(getCacheKey(username));
+        Integer retryCount = (Integer) caffeineCache.getCache(getCacheKey(username));
 
         if (retryCount == null)
         {
@@ -62,7 +63,7 @@ public class SysPasswordService
         if (!matches(user, password))
         {
             retryCount = retryCount + 1;
-            redisCache.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
+            caffeineCache.setCacheWithExpiration(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
             throw new UserPasswordNotMatchException();
         }
         else
@@ -78,9 +79,9 @@ public class SysPasswordService
 
     public void clearLoginRecordCache(String loginName)
     {
-        if (redisCache.hasKey(getCacheKey(loginName)))
+        if (caffeineCache.isKeyExists(getCacheKey(loginName)))
         {
-            redisCache.deleteObject(getCacheKey(loginName));
+            caffeineCache.deleteCacheByKey(getCacheKey(loginName));
         }
     }
 }

+ 4 - 4
fdapfe-framework/src/main/java/com/cn/fdapfe/framework/web/service/SysRegisterService.java

@@ -1,5 +1,6 @@
 package com.cn.fdapfe.framework.web.service;
 
+import com.cn.fdapfe.common.core.redis.CaffeineCache;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import com.cn.fdapfe.common.constant.CacheConstants;
@@ -7,7 +8,6 @@ import com.cn.fdapfe.common.constant.Constants;
 import com.cn.fdapfe.common.constant.UserConstants;
 import com.cn.fdapfe.common.core.domain.entity.SysUser;
 import com.cn.fdapfe.common.core.domain.model.RegisterBody;
-import com.cn.fdapfe.common.core.redis.RedisCache;
 import com.cn.fdapfe.common.exception.user.CaptchaException;
 import com.cn.fdapfe.common.exception.user.CaptchaExpireException;
 import com.cn.fdapfe.common.utils.MessageUtils;
@@ -33,7 +33,7 @@ public class SysRegisterService
     private ISysConfigService configService;
 
     @Autowired
-    private RedisCache redisCache;
+    private CaffeineCache caffeineCache;
 
     /**
      * 注册
@@ -101,8 +101,8 @@ public class SysRegisterService
     public void validateCaptcha(String username, String code, String uuid)
     {
         String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, "");
-        String captcha = redisCache.getCacheObject(verifyKey);
-        redisCache.deleteObject(verifyKey);
+        String captcha = (String) caffeineCache.getCache(verifyKey);
+        caffeineCache.deleteCacheByKey(verifyKey);
         if (captcha == null)
         {
             throw new CaptchaExpireException();

+ 6 - 5
fdapfe-framework/src/main/java/com/cn/fdapfe/framework/web/service/TokenService.java

@@ -4,6 +4,8 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import javax.servlet.http.HttpServletRequest;
+
+import com.cn.fdapfe.common.core.redis.CaffeineCache;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -12,7 +14,6 @@ import org.springframework.stereotype.Component;
 import com.cn.fdapfe.common.constant.CacheConstants;
 import com.cn.fdapfe.common.constant.Constants;
 import com.cn.fdapfe.common.core.domain.model.LoginUser;
-import com.cn.fdapfe.common.core.redis.RedisCache;
 import com.cn.fdapfe.common.utils.ServletUtils;
 import com.cn.fdapfe.common.utils.StringUtils;
 import com.cn.fdapfe.common.utils.ip.AddressUtils;
@@ -52,7 +53,7 @@ public class TokenService
     private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L;
 
     @Autowired
-    private RedisCache redisCache;
+    private CaffeineCache caffeineCache;
 
     /**
      * 获取用户身份信息
@@ -71,7 +72,7 @@ public class TokenService
                 // 解析对应的权限以及用户信息
                 String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
                 String userKey = getTokenKey(uuid);
-                LoginUser user = redisCache.getCacheObject(userKey);
+                LoginUser user = (LoginUser) caffeineCache.getCache(userKey);
                 return user;
             }
             catch (Exception e)
@@ -101,7 +102,7 @@ public class TokenService
         if (StringUtils.isNotEmpty(token))
         {
             String userKey = getTokenKey(token);
-            redisCache.deleteObject(userKey);
+            caffeineCache.deleteCacheByKey(userKey);
         }
     }
 
@@ -150,7 +151,7 @@ public class TokenService
         loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
         // 根据uuid将loginUser缓存
         String userKey = getTokenKey(loginUser.getToken());
-        redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
+        caffeineCache.setCacheWithExpiration(userKey, loginUser, expireTime, TimeUnit.MINUTES);
     }
 
     /**

+ 11 - 11
fdapfe-system/src/main/java/com/cn/fdapfe/system/service/impl/SysConfigServiceImpl.java

@@ -3,12 +3,13 @@ package com.cn.fdapfe.system.service.impl;
 import java.util.Collection;
 import java.util.List;
 import javax.annotation.PostConstruct;
+
+import com.cn.fdapfe.common.core.redis.CaffeineCache;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.cn.fdapfe.common.annotation.DataSource;
 import com.cn.fdapfe.common.constant.CacheConstants;
 import com.cn.fdapfe.common.constant.UserConstants;
-import com.cn.fdapfe.common.core.redis.RedisCache;
 import com.cn.fdapfe.common.core.text.Convert;
 import com.cn.fdapfe.common.enums.DataSourceType;
 import com.cn.fdapfe.common.exception.ServiceException;
@@ -29,7 +30,7 @@ public class SysConfigServiceImpl implements ISysConfigService
     private SysConfigMapper configMapper;
 
     @Autowired
-    private RedisCache redisCache;
+    private CaffeineCache caffeineCache;
 
     /**
      * 项目启动时,初始化参数到缓存
@@ -64,7 +65,7 @@ public class SysConfigServiceImpl implements ISysConfigService
     @Override
     public String selectConfigByKey(String configKey)
     {
-        String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));
+        String configValue = Convert.toStr(caffeineCache.getCache(getCacheKey(configKey)));
         if (StringUtils.isNotEmpty(configValue))
         {
             return configValue;
@@ -74,7 +75,7 @@ public class SysConfigServiceImpl implements ISysConfigService
         SysConfig retConfig = configMapper.selectConfig(config);
         if (StringUtils.isNotNull(retConfig))
         {
-            redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
+            caffeineCache.setCache(getCacheKey(configKey), retConfig.getConfigValue());
             return retConfig.getConfigValue();
         }
         return StringUtils.EMPTY;
@@ -120,7 +121,7 @@ public class SysConfigServiceImpl implements ISysConfigService
         int row = configMapper.insertConfig(config);
         if (row > 0)
         {
-            redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
+            caffeineCache.setCache(getCacheKey(config.getConfigKey()), config.getConfigValue());
         }
         return row;
     }
@@ -137,13 +138,13 @@ public class SysConfigServiceImpl implements ISysConfigService
         SysConfig temp = configMapper.selectConfigById(config.getConfigId());
         if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey()))
         {
-            redisCache.deleteObject(getCacheKey(temp.getConfigKey()));
+            caffeineCache.deleteCacheByKey(getCacheKey(temp.getConfigKey()));
         }
 
         int row = configMapper.updateConfig(config);
         if (row > 0)
         {
-            redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
+            caffeineCache.setCache(getCacheKey(config.getConfigKey()), config.getConfigValue());
         }
         return row;
     }
@@ -164,7 +165,7 @@ public class SysConfigServiceImpl implements ISysConfigService
                 throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
             }
             configMapper.deleteConfigById(configId);
-            redisCache.deleteObject(getCacheKey(config.getConfigKey()));
+            caffeineCache.deleteCacheByKey(getCacheKey(config.getConfigKey()));
         }
     }
 
@@ -177,7 +178,7 @@ public class SysConfigServiceImpl implements ISysConfigService
         List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
         for (SysConfig config : configsList)
         {
-            redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
+            caffeineCache.setCache(getCacheKey(config.getConfigKey()), config.getConfigValue());
         }
     }
 
@@ -187,8 +188,7 @@ public class SysConfigServiceImpl implements ISysConfigService
     @Override
     public void clearConfigCache()
     {
-        Collection<String> keys = redisCache.keys(CacheConstants.SYS_CONFIG_KEY + "*");
-        redisCache.deleteObject(keys);
+        caffeineCache.deleteCacheByPattern(CacheConstants.SYS_CONFIG_KEY + "*");
     }
 
     /**

+ 1 - 0
sql/createDB.sql

@@ -0,0 +1 @@
+CREATE DATABASE fdapfe CHARACTER SET utf8 COLLATE utf8_general_ci;