Skip to content

Instantly share code, notes, and snippets.

Created September 20, 2016 00:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
private static CurrencyExchange GetCurrencyRate(DateTime date)
var key = date.Date.ToString("yyyy-MM-dd");
return _cache.GetOrAdd(key, () =>
Console.WriteLine($"{DateTime.UtcNow}: Fetching from service");
var response = _httpClient.GetAsync("" + key + "?base=USD").Result;
var json = response.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<CurrencyExchange>(json);
}, new TimeSpan(0, 0, 0, 30));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment