Spring cache logging on @Cacheable hit(在@Cacheable Hit上登录Spring缓存)
问题描述
当前我正在使用一个Spring缓存和@Cacheable/@CacheEvict批注。
我希望获得类似"INFO: i got those values from the cache, NOT from the host. awesome"
有没有一种简单明了的方法来做到这一点?我们使用的显然是slf4jbtw,如果您对此感兴趣的话。
Spring
推荐答案本身在trace级别的org.springframework.cache记录器下记录它的一些缓存抽象行为。因此,如果您将org.springframework.cache记录器下的日志附加到适当的附加器,就会有一些关于控制台的有用信息。如果您使用的是Logback,您可以在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>
使用此配置,您应该在控制台上看到如下内容:
关键字‘Page Request[Number:0,Size 20,Sort:空]’的缓存条目 在缓存‘Person’中找到
这篇关于在@Cacheable Hit上登录Spring缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在@Cacheable Hit上登录Spring缓存
基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- Struts2 URL 无法访问 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
