Caffeine cache metrics don't work with caches created via spring.cache.cache-names as the caches don't seem to record statistics.

See https://github.com/izeye/spring-boot-throwaway-branches/tree/cache-caffeine for a sample project to reproduce this.

If a custom Caffeine bean with recordStats() is provided, the metrics work.

See https://github.com/izeye/spring-boot-throwaway-branches/tree/cache-caffeine-custom for an updated one.

Comment From: dreis2211

Don't you have to configure spring.cache.caffeine.spec=recordStats?

Comment From: izeye

@dreis2211 Thanks! You're right.

Sorry for the noise.

Comment From: snicoll

Thanks @dreis2211

@izeye Spring Boot exposes cache metrics if available but does not enable cache metrics automatically.