Caching in ASP.NET 2.0


Dot Net Build

Introduction

Caching is a technique of storing a copy of data in memory. For example, you may cache the a page or the results of a query. The advantage of caching is to build better performance into your application. Accessing cached data in memory is much faster than re-building a page or re-querying the database.

There are two types of caching in asp.net 2.0:

  1. Output Caching
  2. Data Caching
  1. Output Caching

    Output caching stores an HTML page in a cache that will not refresh until your specified duration time passes.

    <%@ OutputCache Duration=”30″ VaryByParam=”None” %>.

    Duration -> Allows you to specify time in seconds.

    VaryByParam -> Output based on query string.

    <%@ OutputCache Duration=”30″ VaryByParam=”UserID” %>.

    Result
    1


    The date/time will refresh automatically after 30 seconds if you put the following code on a page load event.

protected void Page_Load(object sender, EventArgs e)
{

LabelDate.Font.Bold = true;

LabelDate.Font.Italic = true;

LabelDate.Text = “The DateTime is now:<br/>”;

View original post 233 more words