Metrics
Redis Cache Java uses Micrometer to publish metrics for monitoring cache performance.
Enabling Metrics
To enable metrics, set a MeterRegistry in your RedisCacheConfiguration:
RedisCacheConfiguration config = RedisCacheConfiguration.defaultConfig()
.meterRegistry(registry);
Available Metrics
The following metrics are published:
| Name | Tags | Type | Description |
|---|---|---|---|
|
|
Counter |
The number of times cache lookup methods have returned a cached (hit) or uncached (miss) value. |
|
Counter |
The number of entries added to the cache. |
|
|
Counter |
The number of times the cache was evicted. |
|
|
Timer |
Cache get latency |
|
|
Timer |
Cache put latency |
|
|
Timer |
Cache eviction latency |
|
|
|
Counter |
The number of times local cache lookup methods have returned a cached (hit) or uncached (miss) value. |
|
Counter |
The number of times the local cache was evicted. |
All metrics expose their corresponding cache name as a tag: name=<cache>.
|
Example Configuration
@Configuration
public class CacheConfig {
@Bean
public CacheManager cacheManager(RedisClient client, MeterRegistry meterRegistry) {
RedisCacheConfiguration config = RedisCacheConfiguration.defaultConfig()
.meterRegistry(meterRegistry)
.entryTtl(Duration.ofMinutes(10));
return RedisCacheManager.builder(client)
.defaults(config)
.build();
}
}