Spring cache logging on @Cacheable hit
Spring itself logs some of its Caching Abstractions behaviors under the org.springframework.cache
logger in trace
level. So, if you append logs under the org.springframework.cache
logger to an appropriate appender, you would have some useful information on, say, the console. If you're using Logback, you could use something like the following in your logback.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
<logger name="org.springframework.cache" level="trace">
<appender-ref ref="STDOUT" />
</logger>
</configuration>
With this configuration, you should see something like following on your console:
Cache entry for key 'Page request [number: 0, size 20, sort: null]' found in cache 'persons'
You can enable trace level logging.
Eg., in application.properties put 'trace=true'.
Spring logging documentation
And for Spring Boot 2 you can add in your application.properties:
logging.level.org.springframework.cache=TRACE