How to use cache in an action?
Microsoft Net Framework

1) In cache key item 

public const string MostViewedProduct = "MostViewedProduct";

 

2) In IproductService 

 IEnumerable<Product_LookUp_MostViewedProductList_Result> GetProductListByMostViewedProducts(Boolean useCache);

 

3) In product service

public IEnumerable<Product_LookUp_MostViewedProductList_Result> GetProductListByMostViewedProducts(bool useCache)
        {
            if (useCache)
            {
                if (_cache.Contains(CacheItemKeys.MostViewedProduct))
                {
                    var model = _cache.Get<IEnumerable<Product_LookUp_MostViewedProductList_Result>>(CacheItemKeys.MostViewedProduct);

                    return model;
                }
                else
                {
                    var mostviewedproductlist = _unitOfWork.Product_LookUp_MostViewedProductListRepository.ExecWithStoreProcedure("Product_LookUp_MostViewedProductList");
                    _cache.Add(CacheItemKeys.MostViewedProduct, mostviewedproductlist);
                    return mostviewedproductlist;
                }

            }
            else
            {
                var mostviewedproductlist = _unitOfWork.Product_LookUp_MostViewedProductListRepository.ExecWithStoreProcedure("Product_LookUp_MostViewedProductList");

                return mostviewedproductlist;
            };
        }

 

4) In controller Action
    public ActionResult UCHomeProductByMostViewed()
        {
            var mostviewedmodel = _productService.GetProductListByMostViewedProducts(true).ToList();
            return View(mostviewedmodel);
        }

Share This with your friend by choosing any social account


Upcoming Articles
You may also read following recent Post
Copyright Future Minutes © 2015- 2024 All Rights Reserved.   Terms of Service  |   Privacy Policy |  Contact US|  Pages|  Whats new?
Update on: Dec 20 2023 05:10 PM
03
07

New Messages

George Floyd
  • Edit Post Edit This Post within a Hour
  • Hide Chat Hide This Post
  • Delete Chat If inappropriate Post By Mistake
  • Report Inappropriate Chat
  • 4.5kb
  • Hi James! Please remember to buy the food for tomorrow! I’m gonna be handling the gifts and Jake’s gonna get the drinks
  • Hi James! Please remember to buy the food for tomorrow! I’m gonna be handling the gifts and Jake’s gonna get the drinks
  • Hi James! Please remember to buy the food for tomorrow! I’m gonna be handling the gifts and Jake’s gonna get the drinks