public async Task <ActionResult <ProductDTO> > GetProductsAsync([FromQuery] ProductQueryDTO productQueryDTO) { if (productQueryDTO == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var projectQuery = _mapper.Map <ProductQuery>(productQueryDTO); var cacheKey = $"{nameof(TestController)}_{nameof(GetProductsAsync)}_{Request.QueryString.Value}"; var gotCache = await _cache.GetCacheAsync <Product>("notExist"); Console.WriteLine(gotCache is null); // await _cache.CreateCacheAsync<Product>( // "notExist", // async () => await Task<string>.Run(() => { return new Product { PId = Guid.NewGuid() }; }), // options => options.SetSlidingExpiration(TimeSpan.FromSeconds(15))); await _cache.CreateCacheAsync <Product>( "notExist", () => { return(new Product { PId = Guid.NewGuid() }); }, options => options.SetSlidingExpiration(TimeSpan.FromSeconds(15))); gotCache = await _cache.GetCacheAsync <Product>("notExist"); Console.WriteLine(gotCache is null); // // sync type // var syncProduct = // await _cache.CreateOrGetCacheAsync<IEnumerable<Product>>("syncProduct", // () => _repository.GetProductsSync(projectQuery), // options => options.SetSlidingExpiration(TimeSpan.FromSeconds(15))); // Console.WriteLine("----------- sync project" + syncProduct.First().Description); var pagedProducts = await _cache.CreateOrGetCacheAsync <PagedListBase <Product> >(cacheKey, async() => await _repository.GetProducts(projectQuery), options => options.SetSlidingExpiration(TimeSpan.FromSeconds(15))); var filterProps = new Dictionary <string, object>(); filterProps.Add("name", projectQuery.Name); filterProps.Add("description", projectQuery.Description); Response.SetPaginationHead(pagedProducts, projectQuery, filterProps, values => _generator.GetUriByAction(HttpContext, controller: "Product", action: "GetProducts", values: values), meta => JsonSerializer.Serialize(meta, new JsonSerializerOptions { Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) ); var mappedProducts = _mapper.Map <IEnumerable <ProductDTO> >(pagedProducts); return(Ok(mappedProducts.ToDynamicIEnumerable(projectQuery.Fields))); }