public async Task <BaseCustomerDto[]> GetCustomers() { const string cacheKey = CacheKeyConstants.CustomersListCacheKey; var cachedCustomersBytes = await _distributedCache.GetAsync(cacheKey); if (null == cachedCustomersBytes || !cachedCustomersBytes.Any()) { var customers = await _customerQueryService.GetCustomers(); _ = _distributedCache.SetAsync(cacheKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(customers)), new DistributedCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(_optionsCachingTime.Value.CustomerList) }); return(customers); } return(JsonConvert.DeserializeObject <BaseCustomerDto[]>(Encoding.UTF8.GetString(cachedCustomersBytes))); }
public async Task <ActionResult <BaseCustomerDto[]> > GetCustomers() { return(Ok(await _customerQueryService.GetCustomers())); }