Web
Analytics
data caching in asp.net c# example | Angular | ASP.NET Tutorials

For Consultation : +91 9887575540

Stay Connected :

What is Caching

Ø Caching provides a way of storing frequently accessed data and reusing that data.

ØImprove performance of web application

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CachingEx.Controllers
{

    public class HomeController : Controller
    {
        // GET: Home
        
        [OutputCache(Duration = 5, Location =System.Web.UI.OutputCacheLocation.Any , NoStore =true, VaryByParam = "none")]
        public ActionResult Index()
        {
            return Content("Date Time is " + DateTime.Now.ToLongTimeString());
        }
        [OutputCache(Duration = 20, Location = System.Web.UI.OutputCacheLocation.Any, NoStore = true, VaryByParam = "id")]
        public ActionResult GetEmp(int id)
        {
            return Content("Emp Id is "+ id +" Curremt Date Time is " + DateTime.Now.ToLongTimeString());
        }
        [OutputCache(CacheProfile ="Admin")]
        public ActionResult GetEmp2()
        {
            return Content("Date Time is " + DateTime.Now.ToLongTimeString());
        }
    }
}