コード例 #1
0
        public async Task <ExchangeRatesResponse> GetRates(ExchangeRatesRequest request)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var cacheKey = BuildCacheKey(request);
            var response = _Cache.Get(cacheKey) as ExchangeRatesResponse;

            if (response is null)
            {
                response = await _Access.GetRates(request);

                _Cache.Add(cacheKey, response, new CacheItemPolicy());
            }

            return(response);
        }
コード例 #2
0
        private string BuildCacheKey(ExchangeRatesRequest request)
        {
            var cacheKey = $"{request.BaseCurrency}|{request.Date.ToString("yyyyMMdd", CultureInfo.InvariantCulture)}";

            return(cacheKey);
        }