遇到一个奇怪的问题,我用 @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/