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

cache.gets

result=hit|miss

Counter

The number of times cache lookup methods have returned a cached (hit) or uncached (miss) value.

cache.puts

Counter

The number of entries added to the cache.

cache.evictions

Counter

The number of times the cache was evicted.

cache.gets.latency

Timer

Cache get latency

cache.puts.latency

Timer

Cache put latency

cache.evictions.latency

Timer

Cache eviction latency

cache.local.gets

result=hit|miss

Counter

The number of times local cache lookup methods have returned a cached (hit) or uncached (miss) value.

cache.local.evictions

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();
    }
}

Monitoring

Use these metrics to monitor:

  • Cache hit ratio: cache.gets{result=hit} / cache.gets

  • Cache performance: cache.gets.latency, cache.puts.latency

  • Cache usage: cache.puts, cache.evictions

  • Local cache effectiveness: cache.local.gets{result=hit} / cache.local.gets