From ccbaf3737e60bd234b3f9fdd1938db9a02ea0f25 Mon Sep 17 00:00:00 2001 From: FlyInWind <2518509078@qq.com> Date: Thu, 27 Oct 2022 11:14:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=20RedisCaffeineCache#getKey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/cache/support/RedisCaffeineCache.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/pig4cloud/plugin/cache/support/RedisCaffeineCache.java b/src/main/java/com/pig4cloud/plugin/cache/support/RedisCaffeineCache.java index 5bc0818..7959525 100755 --- a/src/main/java/com/pig4cloud/plugin/cache/support/RedisCaffeineCache.java +++ b/src/main/java/com/pig4cloud/plugin/cache/support/RedisCaffeineCache.java @@ -45,6 +45,8 @@ public class RedisCaffeineCache extends AbstractValueAdaptingCache implements Ca private final String cachePrefix; + private final String getKeyPrefix; + private final Duration defaultExpiration; private final Duration defaultNullValuesExpiration; @@ -64,6 +66,12 @@ public RedisCaffeineCache(String name, RedisTemplate stringKeyRe this.stringKeyRedisTemplate = stringKeyRedisTemplate; this.caffeineCache = caffeineCache; this.cachePrefix = cacheConfigProperties.getCachePrefix(); + if (StringUtils.hasLength(cachePrefix)) { + this.getKeyPrefix = name + ":" + cachePrefix + ":"; + } + else { + this.getKeyPrefix = name + ":"; + } this.defaultExpiration = cacheConfigProperties.getRedis().getDefaultExpiration(); this.defaultNullValuesExpiration = cacheConfigProperties.getRedis().getDefaultNullValuesExpiration(); this.expires = cacheConfigProperties.getRedis().getExpires(); @@ -183,8 +191,7 @@ protected Object lookup(Object key) { } protected Object getKey(Object key) { - return this.name.concat(":").concat( - StringUtils.hasLength(cachePrefix) ? cachePrefix.concat(":").concat(key.toString()) : key.toString()); + return this.getKeyPrefix + key; } protected Duration getExpire(Object value) {