Example #1
0
        private RateResult GetLatest()
        {
            RateResult rates;
            var        nextCallTime = _memoryCacheService.GetTimeForNextCall();

            if (nextCallTime > DateTime.UtcNow)
            {
                rates = _memoryCacheService.GetLatestFromCache();
            }
            else
            {
                try
                {
                    rates = _rateClient.GetLatest();
                    _memoryCacheService.SaveLatestToCache(rates);
                    _memoryCacheService.UpdateTimeForNextCall();
                }
                catch (Exception ex)
                {
                    rates = _memoryCacheService.GetLatestFromCache();
                }
            }
            //save to cashe
            return(rates);
        }