Ekansh Gautam
Ekansh Gautam

Reputation: 55

@Cacheable not creating cache keys when called from a method having @transactional annotation in spring boot

ran into a strange issue, I annotated my controller with @Transactional(just for testing) and it took me by surprise that internally when it hits the method with @cacheable annotation it is not creating any cache keys

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

method with @cacheable issue.

@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}

Internally geography service helper calls api manager directly with forceReload = false.

Am I missing something silly?

Upvotes: 1

Views: 249

Answers (1)

Pushpendra Patel
Pushpendra Patel

Reputation: 26

Hey buddy just wait for transaction to get commit and you will see what you want to see.

Upvotes: 1

Related Questions