I am using azure managed identity and below code generates the required token to authenticate the api's. I am using <PackageReference Include="Azure.Identity" Version="1.4.0" />
var credential = new ManagedIdentityCredential();
var accessToken = await credential.GetTokenAsync(new Azure.Core.TokenRequestContext(new[] {"my_scope"}));
return accessToken.Token;
Now in each api call I am calling above method to get token. Question is what are the ways to cache this token and refresh automatically? Is this something inbuild available?