Content Caching

Busy sites often consist of a number of different components and pages that are supplied to the clients. Often, many of these components are the same. For example, static images and HTML page elements are often sent back to a client a number of times, but it doesn't make sense to keep reading the raw content of these files and sending it to clients each time.

Instead, this information can be retrieved from memory if the file has been requested a number of times. IIS 6 improves on the original model by also taking into account how the pages are accessed over the range of a site, dynamically adjusting the cache contents according to site usage.

IIS also improves other areas of the caching process. ISAPI filters can still be cached in memory, just as they could in IIS 5. Other improvements in IIS 6 affect the way ASP content is cached and how the static data caching system works.

Irrespective of the item being cached, IIS 6 can now be configured to use as much as 64GB of memory for the cache. This should be more than adequate to hold the information for most very large sites or a high number of smaller ones, although you will obviously need a fairly significant piece of hardware to support that.

ASP Content

In IIS 5, ASP pages were compiled and executed with the compiled versions stored in memory. This enabled frequently requested pages to be sent back from memory. However, if clients visited a number of pages, it was possible for some of these pages to be removed from the cache before they were actually used.

IIS 6 still executes ASP pages in the same way, and it still keeps a copy of the compiled version in memory. The difference is that it also keeps a copy of the compiled version in memory and, if necessary, stores it on disk as well. Now if an item drops out of the memory cache, IIS can still load a ready-compiled version from the disk, which is quicker than reading the original and re-executing and compiling it.

Actually, the rules are a bit stricter on this. ASP templates are stored on disk only when the memory cache is full. Also, an ASP page should have been accessed at least twice before it is considered for the disk cache.

graphics/does_icon.gif CACHING IS NOT COMPILING

Don't mistake ASP template caching for the more efficient and speedier just-in-time compilation that ASP.NET uses. ASP.NET basically compiles pages to binary code, whereas ASP pages are still interpreted more or less line by line.

You can control how many files are cached and stored and where they are cached and stored through the Metabase or through IIS Manager. The Metabase parameters can be set on a Web server, site, directory, or virtual directory and include

  • AspBufferingOn? This enables or disables ASP buffering?the act of storing the output from an ASP execution in memory before sending to a client. The default is set to true. If set to false, the output is sent directly to the client as it becomes available. This can actually reduce performance by placing more loading on the management of the response.

  • AspScriptEngineCacheMax? Specifies the maximum number of scripting engines that ASP pages keep cached in memory. By increasing this number, you can improve performance by caching more of the templates in memory. The default is 120.

  • AspScriptFileCacheSize? Specifies the number of precompiled script files to store in the in-memory ASP template cache. A value of 0 disables the cache (not recommend), -1 caches all pages, and any other positive value specifies the size. The default value is 500.

  • AspMaxDiskTemplateCacheFiles? Specifies the maximum number of files that can be stored in the disk cache. The default value is 4294967295, which Windows actually uses to specify an unlimited number (although 4.3 billion seems pretty unlimited already). Any number below this limits it to that size.

  • AspDiskTemplateCacheDirectory? The location in which the disk cache of the files will be stored. The default value is %systemroot%\systemroot\inetsrv\ASP Compiled Templates.

If you want to monitor the performance of the template cache, you can use the Templates Cached performance counter. This was also available in IIS 5 and counts the number of cached ASP files both on disk and in memory. To get statistics only on those in memory, use the AspInMemoryTemplatesCached counter.

To control the ASP caching parameters within IIS Manager, use the Cache Options tab (available by right-clicking on the Web Site folder, choosing Properties and then clicking on the Configuration button within the Home Directory panel). You can see an example of the configuration window in Figure 5.1.

Figure 5.1. Changing ASP caching parameters.


The configurable properties match those listed previously in the metabase descriptions. However, some are controlled by a number of entries?the AspScriptFileCacheSize, for example.

Static Content

It seems a little wasteful to constantly use a worker process to process the request for a static element if it already exists in the cache. So IIS 6 doesn't use a worker process for this purpose.

Instead, the HTTP.sys kernel mode driver's role is to respond with the contents of static data if it exists in the in-memory cache of static information. Only if the item in question is not in the cache is a worker process brought into play.

The system can do this because the HTTP.sys driver cannot technically access the file system (mostly for security and performance reasons), but it can access the shared memory used to store cached data.

The actual cache itself is still configured and managed by the registry parameters rather than the Metabase.