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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user