ASP.NET Caching
ASP.NET caching lets you reuse pages that the server has already rendered. ASP.NET provides two types of caching that the IIS administrator and developer can use to create high-performance IIS applications: data caching and output caching.
Data caching. ASP.NET data caching lets a developer programmatically store arbitrary data objects in server memory. Programmatically retrieving data from memory on the IIS server is much faster than retrieving it from a disk-based storage system (e.g., a Microsoft SQL Server database, an XML schema, another proprietary format such as Microsoft Exchange Server, or a directory service such as Active DirectoryAD).
Depending on your application's requirements, you can use one of several techniques to add an item to the Cache object. Let's look at one example of how an ASP.NET application developer can cause an item to persist in the ASP.NET data cache, then retrieve that item.
Think of the ASP.NET data cache in terms of name-value pairs. The Visual Basic .NET code
Cache.Insert("MyDataView", _dataviewObj)
inserts a sample dataview of type object into the data cache and associates the name MyDataView with the sample dataview.
Retrieving data from the ASP.NET data cache is equally simple. The code in Listing 1 retrieves the data to which I assigned the name MyDataView, then assigns the data to a variable named Source. The code then determines whether the data still exists in the cache; if so, the code displays the data in a DataGrid server control.
Although you might be tempted to use the ASP.NET data cache for everything, a more practical approach is to use the data cache to store static information. You won't see much benefit of reading from the data cache if your application is constantly writing to it.
Output caching. ASP.NET output caching stores the contents of dynamic ASP.NET pages on any HTTP 1.1 cache-capable device, such as a proxy server in the request or response stream. By caching this output, you can prevent the need to execute subsequent requests for the ASP.NET page. Output caching is a powerful and relatively simple way to dramatically improve your ASP.NET application performance. When you cache your site's most frequently accessed pages, you significantly increase your IIS server's throughput (usually measured in requests per second).
You can use two methods to implement ASP.NET output caching. One technique uses the HttpCachePolicy class to programmatically leverage a set of APIs and involves a low-level programmatic API (discussion of which is beyond the scope of this article). The other technique, which will meet most of your needs, leverages the @ OutputCache directivea high-level declarative API.
To use the @ OutputCache directive, you simply add it to the top of an ASP.NET page that you want to cache. For example,
<%@ OutputCache Duration="45" _
VaryByParam="None" %>
sets an expiration of 45 seconds for the cached output of a dynamically generated page. The Duration and VaryByParam attributes are required parameters. The Duration attribute is the time, in seconds, that you want the page to remain cached. In general, the Duration value should match the interval you use to refresh your ASP.NET page. For example, if you update your home page every 4 hours, the Duration value should be 4 hours. The VaryByParam attribute is a list of strings, separated by semicolons, that corresponds to an HTML query string value that the ASP.NET page sends to IIS through the GET method or to a parameter that the ASP.NET page sends through the HTML POST method. When you set the VaryByParam attribute to multiple parameters, the output cache contains a different version of the requested ASP.NET page for each specified parameter. Setting the VaryByParam parameter to None caches every version of the page, regardless of which HTML GET or POST parameter is sent to the ASP.NET page.
The Cost of Better Performance
ASP.NET is much different from and much more powerful than ASP. IIS administrators will find ASP.NET to be an absolute pleasure because it flat out outperforms ASP. Also, ASP.NET applications are much easier to deploy than ASP applications. However, some environments will find installing the .NET Framework difficult because it requires 22MB of overhead. And your developers must traverse ASP.NET's steep learning curve. But after developers have spent some time learning this new technology, they'll be able to design beautifully performing applications.
End of Article