I want to implement idempotency-key for POST method in springboot.
eg: http://localhost:8020/project/createStudent
Above is my POST method invocation. I will pass student details in body along with idempotency-key in header.
What I want to achieve is that when the request is sent, then the idempotency-key and api response must be stored in a key cache only on successful creation of record. On subsequent POST requests made with same data, the cache should be verified against the idempotency-key for duplicates. And if the key is found then just send Conflict(409) response. I know how to send an idempotency key in header and I also know that we could use @Cacheable in springboot to cache the response. But, I haven't found a solution to below
- How to implement @Cachable to store the cache based on idempotency key sent from client. (Every distinct record will have a new idempotency-key)
- How to verify if a response object/record is present in cache by passing an idempotency-key.
There are many solution on the internet but they don't talk about saving and retrieving cache based on idempotency-key. They just ask to define a method with @Cacheable and rest will happen automatically.