Spring cache logging on @Cacheable hit

后端 未结 4 1050
花落未央
花落未央 2021-02-05 03:08

Currently I am working with a Spring Cache and the @Cacheable/@CacheEvict annotations.

I would like to get some sort of a console log statement

4条回答
  •  眼角桃花
    2021-02-05 03:45

    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:

    
    
        
            
                %msg%n
            
        
    
        
            
        
    
    

    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'

提交回复
热议问题