Search This Blog

Sunday, July 14, 2019

OutputCache Filter MVC and Location property



  • It 's type of Action filter
  • This filter is used to cache data of particular action method  for a specific time 
  • To set the time use Duration property



       [OutputCache(Duration =20) ]    //Apply filter to Action Method
        public ActionResult Getdate()
        {
            return View();

        }

 //Apply filter to all  Action Method  inside controller
  
   [OutputCache(Duration = 20)]
    public class HomeController : Controller
    {
        // GET: Home
       
        public ActionResult Getdate()
        {
            return View();
        }
        public int gettime()
        {
            return DateTime.Now.Date.Day;
        }

    }

Location Property Caching when we cache data using output cache filter it need some loation  to store that data 

[OutputCache(Duration = 20,Location =System.Web.UI.OutputCacheLocation.Server)]
        public ActionResult Getdate()
        {
            return View();

        }

No comments :