HOW TO: Improve Performance by Caching Pages in ASP.NET
This article was previously published under Q315896 On This PageSUMMARY
This article demonstrates how to improve the performance of ASP.NET applications by caching entire ASP.NET pages with the @ OutputCache page directive. You can also the @ OutputCache page directive to cache specific portions of an ASP.NET page, though this article does not demonstrate this implementation. RequirementsThe following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
Description of the TechniqueWhen you cache information, you place the information in memory. Normally, when IIS receives a request for a page, IIS reads the page from the hard disk and then sends the page. Sometimes, IIS can automatically store information in memory to improve performance. The @ OutputCache directive allows you to hold a page in memory, even if that page does not fit the criteria that IIS uses to determine what information it holds in memory.For example, pages that access a database are run again each time you browse to the page to obtain the latest data. When you use the @ OutputCache directive, the page is held in memory with the results of one query to the database until the specified time period expires. Therefore, you can use the @ OutputCache directive to avoid querying the database every time someone browses to the page. This is very useful for data that does not change frequently. Create an ASP.NET Web Application That Uses @ OutputCacheIn this section, you create an ASP.NET Web application that uses the @ OutputCache page directive to cache the page for a specific time period.
Complete Code ListingNOTE: You may need to modify the Inherits attribute in the following line of code as necessary to reference the name of your project and Web Form:
The code currently assumes that your project is named WebApplication1 and that your Web Form is named WebForm1.Verify That It Works
REFERENCES
For more information, refer to the following Microsoft Web sites:
ASP.NET Optimization http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaspoptimization.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaspoptimization.asp) 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) 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) @ OutputCache http://msdn2.microsoft.com/en-us/library/hdxfb6cy(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/hdxfb6cy(vs.71).aspx)
| Article Translations
|

Back to the top
