Total Pageviews

17 April 2018

What is caching ?

What is caching and types of caching

This is technique use to increase performance by keeping access data in fast way.The request for a
cached file or data from the actual location

There are three kind of caching

1.Output Caching

 Response.Cache.SetExpires(DateTime.Now.AddMonths(1));
    Response.Cache.SetCacheability(
        HttpCacheability.ServerAndPrivate);
    Response.Cache.SetValidUntilExpires(true);

2.Fragment Caching


Create a user control


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="amrit.ascx.cs" Inherits="WebUserControl" %>
<%@ OutputCache Duration="5" VaryByParam="None" %>

<asp:Label ID="lblTime" runat="server" Font-Bold="true" ForeColor="Blue" />


create a page and define datetime on load event

protected void Page_Load(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToString();
}



<%@ Register src="amrit.ascx" tagname="WebUserControl" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Fragment Caching in Asp.Net with Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>Refresh the Page Time Will Update Only After Every 5 Seconds</p>
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
</div>
</form>
</body>
</html>

3.Data Caching

 Cache.Remove(String key);

No comments:

Post a Comment

Contact Form

Name

Email *

Message *