Expose cache metrics for Redis

This commit adds support for Redis cache metrics. Users can opt-in for
statistics using the "spring.cache.redis.enable-statistics" property.

Closes gh-22701
This commit is contained in:
Stephane Nicoll
2020-10-07 17:20:53 +02:00
parent a099cd9420
commit 34c4c3f235
9 changed files with 335 additions and 1 deletions

View File

@@ -257,6 +257,11 @@ public class CacheProperties {
*/
private boolean useKeyPrefix = true;
/**
* Whether to enable cache statistics.
*/
private boolean enableStatistics;
public Duration getTimeToLive() {
return this.timeToLive;
}
@@ -289,6 +294,13 @@ public class CacheProperties {
this.useKeyPrefix = useKeyPrefix;
}
public boolean isEnableStatistics() {
return this.enableStatistics;
}
public void setEnableStatistics(boolean enableStatistics) {
this.enableStatistics = enableStatistics;
}
}
}

View File

@@ -63,6 +63,9 @@ class RedisCacheConfiguration {
if (!cacheNames.isEmpty()) {
builder.initialCacheNames(new LinkedHashSet<>(cacheNames));
}
if (cacheProperties.getRedis().isEnableStatistics()) {
builder.enableStatistics();
}
redisCacheManagerBuilderCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
return cacheManagerCustomizers.customize(builder.build());
}