in src/AzureCacheOptionsProviderWithToken.cs [131:157]
private async Task EnsureAuthenticationAsync(bool throwOnFailure = true)
{
// Take the lock
if (1 == Interlocked.Exchange(ref _ensureAuthenticationInProgress, 1))
{
// Update is already in progress
return;
}
try
{
if (_tokenAcquiredTime == DateTime.MinValue // Initial token has not yet been acquired
|| (_tokenExpiry - _tokenAcquiredTime) <= TimeSpan.Zero // Current expiry is not valid
|| (_tokenExpiry - DateTime.UtcNow) < (_azureCacheOptions.TokenHeartbeatInterval + _azureCacheOptions.TokenHeartbeatInterval) // Within two heartbeats of expiration
|| _azureCacheOptions.ShouldTokenBeRefreshed(_tokenAcquiredTime, _tokenExpiry)) // Token is due for refresh
{
await AcquireTokenAsync(throwOnFailure).ConfigureAwait(false);
}
await ReauthenticateConnectionsAsync().ConfigureAwait(false);
}
finally
{
// Release the lock
Interlocked.Exchange(ref _ensureAuthenticationInProgress, 0);
}
}