【问题标题】:@Cacheable not creating cache keys when called from a method having @transactional annotation in spring boot@Cacheable 在 Spring Boot 中从具有 @transactional 注释的方法调用时不创建缓存键
【发布时间】:2019-07-01 15:16:40
【问题描述】:

遇到了一个奇怪的问题,我用 @Transactional 注释了我的控制器(仅用于测试),令我惊讶的是,当它在内部使用 @cacheable 注释命中方法时,它没有创建任何缓存键

@Transactional
@RequestMapping(value = "/auth", method = RequestMethod.POST)
public void createAuth() {
    ApplicationContextProvider.getApplicationContext().getBean(GeographyServiceHelper.class).getAggregatedClusterData(1);
}

@cacheable 问题的方法。

@Cacheable(value = "getAllClusterHierarchyHash", key = "\"all_cluster_hirerarchy_map\"", unless = CONDITION_NULL,
        cacheNames = "getAllClusterHierarchyHash")
@CacheEvict(value = "getAllClusterHierarchyHash", key = "\"all_cluster_hirerarchy_map\"",
        condition = "#forceReload", cacheNames = "getAllClusterHierarchyHash", beforeInvocation = true)
public Map<Integer, ClusterDetails> getAllClusterHierarchyHash(Boolean forceReload) {// do something}

内部地理服务助手直接使用 forceReload = false 调用 api 管理器。

我错过了什么傻事吗?

【问题讨论】:

    标签: java spring caching spring-transactions


    【解决方案1】:

    嘿,伙计,只需等待事务提交,您就会看到您想看到的。

    【讨论】:

      猜你喜欢
      • 2019-07-14
      • 2021-06-08
      • 2021-04-25
      • 2018-02-23
      • 2021-07-20
      • 2017-05-22
      • 1970-01-01
      • 2012-08-20
      • 2018-05-06
      相关资源
      最近更新 更多