I've spent good number of hours reading the official documentation, googling StackOverflow, searching through old GitHub issues and diving into the code and still can't figure out how to enable cache metrics exposure through /actuator endpoint.

Could the team please enhance documentation by providing more details in the official documentation here: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#actuator.metrics.supported.cache or at least provide some examples in one of open StackOverflow questions, like this one for instance: https://stackoverflow.com/questions/70345214/redis-cache-metrics-with-prometheusspring-boot (not my question)?

In my project I manually create two beans: LettuceConnectionFactory and RedisTemplate, then I use RedisTemplate object for operations with Redis instance. Looking into https://github.com/spring-projects/spring-boot/commit/34c4c3f2358bc2bd82fc3542b2d31a62ec83715b change, I tried enabling monitoring by setting spring.cache.redis.enable-statistics property but that had no effect. I think the reason is because I configure my own instances of LettuceConnectionFactory and RedisTemplate. The documentations states:

Only caches that are configured on startup are bound to the registry. For caches not defined in the cache’s configuration, such as caches created on the fly or programmatically after the startup phase, an explicit registration is required. A CacheMetricsRegistrar bean is made available to make that process easier.

If I understand correctly CacheMetricsRegistrar assumes that I need to create RedisCacheManager and RedisCache but I don't see how this is related to my RedisTemplate instance. Maybe it's not possible to enable monitoring for RedisTemplate at all? Would really appreciate if someone could clarify these questions and I'll try to spread this knowledge on StackOverflow. 🙏

Comment From: bigunyak

I've now realised, that it's only RedisCache that collects and exposes CacheStatistics, there is nothing like that in RedisTemplate and probably can't be because of a less definitive Redis server access model. So, I guess I'll have to implement my custom monitoring metrics.