如何通过@Cacheable注释记录缓存命中?

问题描述 投票:1回答:1

下面的此类中有一个方法:

    @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以便可以对其进行记录?

spring spring-cache
1个回答
2
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.