Skip to content

Commit

Permalink
fix: AppConfig through exception if calling too frequently, use whats…
Browse files Browse the repository at this point in the history
… in cache
  • Loading branch information
wani-guanxi committed Jan 21, 2025
1 parent bf18ec7 commit 7ce2bab
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,27 @@ public async Task<GetLatestConfigurationResponse>GetLatestConfigurationAsync(Fea
ConfigurationToken = await GetSessionToken(profile)
};

var response = await _appConfigDataClient.GetLatestConfigurationAsync(configurationRequest);
GetLatestConfigurationResponse response;

// If not NextPollConfigurationToken, something wrong with AWS connection.
if(string.IsNullOrWhiteSpace(response.NextPollConfigurationToken)) throw new Exception("Unable to connect to AWS");
try
{
response = await _appConfigDataClient.GetLatestConfigurationAsync(configurationRequest);
}
catch
{
// On exception, could be because of connection issue or
// too frequent call per defined by polling duration, get what's in cache
response = null;
}

// First, update the session token to the newly returned token
_memoryCache.Set(sessionKey, response.NextPollConfigurationToken);
// Update Next Poll configuration token only when one is available.
if(response != null)
{
// First, update the session token to the newly returned token
_memoryCache.Set(sessionKey, response.NextPollConfigurationToken);
}

if((response.Configuration == null || response.Configuration.Length == 0)
if((response?.Configuration == null || response.Configuration.Length == 0)
&& _memoryCache.TryGetValue(configKey, out GetLatestConfigurationResponse configValue))
{
// AppConfig returns empty Configuration if value hasn't changed from last retrieval, hence use what's in cache.
Expand Down

0 comments on commit 7ce2bab

Please sign in to comment.