Help and Support
 

powered byLive Search

INFO: ASP.NET Caching Overview

Article ID:307225
Last Review:May 31, 2007
Revision:4.7
This article was previously published under Q307225
On This Page

SUMMARY

This article provides an introduction to ASP.NET caching.

For additional ASP.NET overviews, refer to the following Microsoft Knowledge Base article:
305140 (http://support.microsoft.com/kb/305140/EN-US/) INFO: ASP.NET Roadmap

Back to the top

MORE INFORMATION

The ASP.NET cache is a general-purpose cache facility for Web applications. It provides both a simple interface for caching and a more advanced interface that exposes expiration and change dependency services.

Caching is an extremely important technique for building high-performance, scalable server applications. Some items that are expensive to construct can be built once and then used for some amount of time before they are considered invalid. These items are stored in memory where they can be efficiently retrieved and used without incurring the cost of reconstructing them.

To learn more about ASP.NET caching features, refer to the following topic in the Microsoft .NET Framework Software Development Kit (SDK) documentation:
ASP.NET Caching Features
http://msdn2.microsoft.com/en-us/library/xsbfdd8c(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/xsbfdd8c(vs.71).aspx)
ASP.NET includes three caching features:
Output Caching
Fragment Caching
Cache APIs

Back to the top

Output Caching

Output caching allows you to store the results that a dynamic page generates. On subsequent requests, the cached output is used to satisfy the request rather than dynamically executing the page code. Output caching is also referred to as page caching.

The following sample illustrates how to cache the output of the page for 30 seconds:

Visual Basic .NET Sample
<%@ Page Language="VB" %>
<%@ OutputCache Duration="30" VaryByParam="*" %>
<script runat=server>
Public Sub Page_Load()
   Response.Write(DateTime.Now.ToString())
End Sub
</script>
				
Visual C# .NET Sample
<%@ Page Language="C#" %>
<%@ OutputCache Duration="30" VaryByParam="*" %>
<script runat=server>
public void Page_Load()
{
   Response.Write(DateTime.Now.ToString());
}
</script>
				
Visual J# .NET Sample
<%@ Page Language="VJ#" %>
<%@ OutputCache Duration="30" VaryByParam="*" %>

<script runat=server>
public void Page_Load()
{
	get_Response().Write(System.DateTime.get_Now().ToString());
}
</script>
				
For more information about output caching, refer to the following topic in the .NET Framework SDK documentation:
Caching ASP.NET Pages
http://msdn2.microsoft.com/en-us/library/06bh14hk(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/06bh14hk(vs.71).aspx)

Back to the top

Fragment Caching

Fragment caching is useful when you need to cache only a subset of a page. This is accomplished by caching the outputs of a user control. Navigation bars, headers, and footers are good candidates for fragment caching.

For more information about fragment caching, refer to the following topic in the .NET Framework SDK documentation:
Caching Portions of an ASP.NET Page
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcachingportionsofaspnetpage.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcachingportionsofaspnetpage.asp)

Back to the top

Cache APIs

Cache Application Programming Interfaces (APIs) allow you to programmatically store arbitrary objects to memory so that your application can save the time and resources that it takes to re-create them. Cache APIs allow you to expire items from the cache based on the following credentials:
Time
File dependencies
Cache key dependencies
For an overview of the cache APIs, refer to the following topic in the .NET Framework SDK documentation:
Caching Application Requests
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcacheapis.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcacheapis.asp)
ASP.NET enables you to easily add, retrieve, and remove items from the cache. For information about adding, retrieving, and removing items from the cache, refer to the following topics in the .NET Framework SDK documentation:
Adding Items to the Cache
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaddingitemstocache.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaddingitemstocache.asp)

Retrieving Values of Cached Items
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconretrievingvaluesofcacheditems.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconretrievingvaluesofcacheditems.asp)

Deleting Items from the Cache
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondeletingitemsfromcache.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondeletingitemsfromcache.asp)

Back to the top


APPLIES TO
Microsoft ASP.NET 1.1
Microsoft ASP.NET 1.0
Microsoft Visual Basic .NET 2003 Standard Edition
Microsoft Visual Basic .NET 2002 Standard Edition
Microsoft Visual C# .NET 2003 Standard Edition
Microsoft Visual C# .NET 2002 Standard Edition
Microsoft Visual J# .NET 2003 Standard Edition

Back to the top

Keywords: 
kbapi kbcaching kbinfo KB307225

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.