【问题标题】:How to log cache hits through @Cacheable annotation?如何通过@Cacheable 注解记录缓存命中?
【发布时间】:2019-03-26 08:10:58
【问题描述】:

在下面这样的类中有一个方法:

    @Override
    @Transactional
    @Cacheable(value = "products", key = "#id")
    public Product getProduct(long id) throws ApplicationException {
        Product product = null;
        try {
            ProductEntity productEntity = productDAO.getProduct(id);
            product = productTransformer.toProduct(productEntity);
        } catch (SystemException ex) {
            throw new ApplicationException(ex.getCode(), ex.getMessage(), "Problem in DataLayer", "Data Layer Error",
                    new Object[] { ex });
        }
        return product;
    }

应用程序运行良好。但是当数据放入缓存时,我希望有一个缓存命中日志。我想通过 log4j.properties 记录它。

如何配置 application.properties 以便记录?

【问题讨论】:

    标签: java spring spring-boot ehcache jcache


    【解决方案1】:

    Spring 在内部以 TRACE 级别记录其缓存工作流。要启用此功能,请在 application.properties 文件中包含以下内容。

    logging.level.org.springframework.cache=TRACE

    【讨论】:

      【解决方案2】:

      包括以下内容应该会有所帮助:

      logging.level.org.springframework.cache=TRACE
      

      【讨论】:

        猜你喜欢
        • 2016-09-13
        • 2021-08-22
        • 1970-01-01
        • 2019-08-28
        • 2012-08-20
        • 2015-05-02
        • 2014-03-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多