java - @Cacheable 在 Spring Boot 中从具有 @transactional 注释的方法调用时不会创建缓存键

标签 java spring caching spring-transactions

遇到一个奇怪的问题,我用 @Transactional 注释了我的 Controller (只是为了测试),令我惊讶的是,在内部它使用 @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 - @Cacheable 在 Spring Boot 中从具有 @transactional 注释的方法调用时不会创建缓存键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54574469/

相关文章:

asp.net - 过期输出缓存 ASP.Net MVC

c# - 创建一串重复字符并缓存它?

java - 使用 postman 休息客户端调试不适用于休息方法 PUT

java - 升级到 Spring 3.2.4 后出现错误 NoClassDefFoundError

Spring Data JPA 使用 SpEL 语法有条件地构建查询

spring - 同一个 VM 中已存在另一个同名 'cacheManager' 的 CacheManager

caching - 对于单个缓存行,单边 RDMA 读取是原子的吗?

java - Maven 布局结构创建。仅资源文件夹可见,未创建 Java 文件夹

java - 在android中查找多边形中的点

java - 可重入ReadWriteLock限制