コード例 #1
0
        public async Task <JsonResult> SearchProduct(string detail)
        {
            List <ModelForProductsList> products = new List <ModelForProductsList>();

            if (!cache.TryGetValue <List <ModelForProductsList> >(detail, out products))
            {
                products = await Task.Run(() => repository.SearchProduct(detail).ToList());

                MemoryCacheEntryOptions options = new MemoryCacheEntryOptions();
                options.AbsoluteExpiration = clock.AddMinutes(3);
                options.SlidingExpiration  = clock.FromMinutes(3);
                cache.Set <List <ModelForProductsList> >(detail, products, options);
            }

            return(Json(products));
        }