Do we have cache to store a variable for 30 mins

Hi Team,   I am searching for an option to store a variable for 30 mins, need to be used for all transactions for other 30 mins   I need to Consume a REST service and the authentication method is OAuth 2.0(Client Credentials). Will call OAuth 2.O token service API-1 to generate a Auth token(Expiry: 30 mins) I would like to store the generated token in a Cache Variable(need to set cache time for 30 mins) With this generated token, will use as "Bearer token" authentication method and call the main API-2 For the next transaction, instead of generating a new token, will make use of stored token from cache variable and call main API-2. Is this possible to replicate? I would like to avoid the the step 1 for all other transactions occur for 30 mins. Which make use of stored token.   Please let me know. 
1 answers

I would use a persistent entity to store the OAuth token and it's createdDate.


Use a scheduled event that runs every X minutes to get the OAuth token and commit it. In this event also look to retrieve all objects with a createdDate over 30 minutes and delete them. If you are expecting to update the token every 30 minutes, maybe run this once every 10 minutes so if there is a problem getting the token, the existing token will still be valid for a while and should hopefully update the next time the event runs.


When you want to use the token, do a retrieve from the database but set an order by createDate and only select the first match. This should be the most recent OAuth token.


I hope this helps.