Home > Uncategorized > Site wide caching in ASP.NET 1.x

Site wide caching in ASP.NET 1.x

ASP.NET supports a feature known as caching. This is where the output of the page is stored in memory, for a short period of time until it is requested again, providing a performance boost. Expecially in IIS6/Win 2003 with it’s kernel mode HTTP.sys implementation.

Implementing this in ASP.NET 1.x would generally mean adding the page directive

<%@OutputCache Duration="5" VaryByParam="none" %>  to each page.

Which could be a big job if it is being fitted retrospectively to a large website.

However, it can be added to the Global.asax thus:

 protected void Application_BeginRequest(Object sender, EventArgs e)

 HttpContext Context = HttpContext.Current;
 HttpResponse resp = Context.Response;
 resp.Cache.SetExpires(DateTime.Now.AddSeconds(60));
 resp.Cache.SetCacheability(HttpCacheability.Server);
}

In asp.net 2.0 this can be added as a parameter in the web.config.

 

 

 

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: