From my microservice(SERVICE-A) I hit a rest api call to another microservice(SERVICE-B) for login and getting a access token and that API will respond with TTL of that token. I need to cache the token till that TTL(seconds) that is responded by SERVICE-B. So my implementation is as below,
@Cacheable("USERTOKEN")
public String getUserToken()
{
//Hits Service-B
//Gets token and TTL as a response from Service-B
//Returns Token or Token with TTL
}
I need to change the above method something as
@Cacheable("USERTOKEN")
public String getUserToken()
{
//Hits Service-B
//Gets token and TTL as a response from Service-B
//Sets expiry time for "USERTOKEN" cache <-- this needs to be added
//Returns Token or Token with TTL
}
Even after returning from getUserToken() if it is possible to setExpiryTime for the "USERTOKEN" cache using the TTL returned by getUserToken() it will be fine. We can set Scheduled for eviction but it is going to be a static time period. But here I need it to be set as dynamic value based on the response from Service-B. How can I achieve this.