From cad250f02a66237258d1e96addd4704a1fdefb2f Mon Sep 17 00:00:00 2001 From: _老马_ <mayuanfei@163.com> Date: 星期三, 17 一月 2024 13:47:44 +0800 Subject: [PATCH] !479 update 优化 使用预扫描实体类提升代码性能 * 优化了数据库字段加解密的缓存机制.在自动配置类启动时,就把有加密注解的类进行缓存,以提高速度. --- ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/manager/CaffeineCacheDecorator.java | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 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 1d02efd..8d1f518 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 @@ -32,17 +32,21 @@ return cache.getNativeCache(); } + public String getUniqueKey(Object key) { + return cache.getName() + ":" + key; + } + @Override public ValueWrapper get(Object key) { - Object o = CAFFEINE.get(key, k -> cache.get(key)); - Console.log("redisson caffeine -> key: " + key + ",value:" + o); + Object o = CAFFEINE.get(getUniqueKey(key), k -> cache.get(key)); + Console.log("redisson caffeine -> key: " + getUniqueKey(key) + ",value:" + o); return (ValueWrapper) o; } @SuppressWarnings("unchecked") public <T> T get(Object key, Class<T> type) { - Object o = CAFFEINE.get(key, k -> cache.get(key, type)); - Console.log("redisson caffeine -> key: " + key + ",value:" + o); + Object o = CAFFEINE.get(getUniqueKey(key), k -> cache.get(key, type)); + Console.log("redisson caffeine -> key: " + getUniqueKey(key) + ",value:" + o); return (T) o; } @@ -63,7 +67,7 @@ public boolean evictIfPresent(Object key) { boolean b = cache.evictIfPresent(key); if (b) { - CAFFEINE.invalidate(key); + CAFFEINE.invalidate(getUniqueKey(key)); } return b; } @@ -80,8 +84,8 @@ @SuppressWarnings("unchecked") @Override public <T> T get(Object key, Callable<T> valueLoader) { - Object o = CAFFEINE.get(key, k -> cache.get(key, valueLoader)); - Console.log("redisson caffeine -> key: " + key + ",value:" + o); + Object o = CAFFEINE.get(getUniqueKey(key), k -> cache.get(key, valueLoader)); + Console.log("redisson caffeine -> key: " + getUniqueKey(key) + ",value:" + o); return (T) o; } -- Gitblit v1.9.3