An API client may retry a request after a timeout without knowing whether the first attempt completed. An idempotency key lets the server return the first attempt's stored result instead of performing the operation again.
Design an IdempotencyKeyStore class:
IdempotencyKeyStore() creates an empty store.int execute(String key, int proposedResult) handles one request.
If key has not appeared before, store and return proposedResult. If the key already exists, ignore proposedResult and return the result stored by the first request.
Keys are case-sensitive. Stored entries remain available for the lifetime of the object.
Example 1:
Input:
Output:
Explanation: The first a request stores 1. Its retries return 1, ignoring the proposed results 3 and 5. Keys b and c have independent entries.
Example 2:
Input:
Output:
Explanation: Only the first request for x stores a result. Every retry replays 10.
Constraints
1 <= key.length <= 100key contains printable ASCII characters.-10^9 <= proposedResult <= 10^9- At most
10^5 calls are made to execute on one object. - Keys never expire during a test case.