Search code examples
springspring-bootehcachespring-boot-actuator

Show entries of cache via Spring Boots Actuator Endpoint /caches


I have a Spring Boot application with Actuator and Caching running. When I call

http://localhost:8080/actuator/caches/myCacheName

I only get some basic information about target, name and cacheManager.

But I want to see all entries of this particular cache.

So is it possible to customize this endpoint that it gives me more information?


Solution

  • you can customize current endpoints by extending them. This is an example using the @EndpointWebExtension annotation to extend the standard info actuator endpoint with more functionality.

    example is taken from here: Extend actuator endpoints

    Here is springs official documentation about extending endpoints: Spring extending endpoints

    @Component
    @EndpointWebExtension(endpoint = InfoEndpoint.class)
    public class InfoWebEndpointExtension {
    
        private InfoEndpoint delegate;
    
        // standard constructor
    
        @ReadOperation
        public WebEndpointResponse<Map> info() {
            Map<String, Object> info = this.delegate.info();
            Integer status = getStatus(info);
            return new WebEndpointResponse<>(info, status);
        }
    
        private Integer getStatus(Map<String, Object> info) {
            // return 5xx if this is a snapshot
            return 200;
        }
    }