Skip to content

Commit

Permalink
简化 RedisCaffeineCache#getKey
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyInWind1 committed Oct 27, 2022
1 parent 5b63f92 commit ccbaf37
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -64,6 +66,12 @@ public RedisCaffeineCache(String name, RedisTemplate<Object, Object> 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();
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ccbaf37

Please sign in to comment.