[英]Spring log if cache is called for @Cacheable
I have a simple spring 3.2 web application, which is connected to a MySQL db. 我有一个简单的spring 3.2 Web应用程序,它连接到MySQL数据库。 My question is simple: I have method in dao, which is annotated with @Cacheable.
我的问题很简单:我在dao中有方法,用@Cacheable注释。 Is there a way to log if the method goes to db, or its result is loaded from cache?
如果方法转到db,或者从缓存加载结果,有没有办法记录? For example, I'd like to see the following log:
例如,我想看到以下日志:
Object with id 'x' was retrieved from database at 23:44:30 / 2015....
Object with id 'x' was retrived from cache at...
Thank you 谢谢
Spring在TRACE
级别的org.springframework.cache
类别下注销缓存命中和未命中。
you can a log message in your service layer if there's going to be a call to your persistence layer. 如果要对持久层调用,则可以在服务层中显示日志消息。 here's a method from some code i'm working where i'm doing this.
这是我正在做的一些代码的方法。 I only get a log entry when the cache isn't hit.
我没有在没有命中缓存时获得日志条目。
@Cacheable(value = CACHE_PICO)
@Transactional(readOnly = true)
@PostAuthorize(PICO_READ + OR + ALLOWED_FOR_ADMIN)
public Pico get(long id) {
log.info("cached missed for pico {}", id);
return _picoRepository.findOne(id);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.