user3462941
user3462941

Reputation: 73

Throw 409 CONFLICT if data is coming from Cache - @Cachable in spring boot

I have implemented caching using spring boot and ehcache. My scenario is about implementing idempotency key for POST method and for that I have created a cache based on idempotency key with @Cacheable annotation. What I want to do is return 409 CONFLICT if cache is present for a given the idempotency key. I have following code in handler class which sends response to a Controller class.

@Cacheable(value="myCache", key="#idempotencyKey")
public DAO createRecord(String userID, String idempotencyKey) {
// database call
return new DAO();
}

What I want to do here is somehow find if the response I am receiving in Controller class is coming from cache. If it is coming from cache then throw 409 CONFLICT by wrapping it in ResponseEntity.

Request for a response as I am stuck at this.

Upvotes: 1

Views: 150

Answers (0)

Related Questions