Caching Profiles <profiles>
The <profiles>
element of the <caching>
element specifies a profile to use for output caching.
Version | Notes |
---|---|
IIS 10.0 | The <profiles> element was not modified in IIS 10.0. |
IIS 8.5 | The <profiles> element was not modified in IIS 8.5. |
IIS 8.0 | The <profiles> element was not modified in IIS 8.0. |
IIS 7.5 | The <profiles> element was not modified in IIS 7.5. |
IIS 7.0 | The <profiles> element of the <caching> element was introduced in IIS 7.0. |
IIS 6.0 | N/A |
The <profiles>
element of the <caching>
element is included in the default installation of IIS 7.
Open Internet Information Services (IIS) Manager:
If you are using Windows Server 2012 or Windows Server 2012 R2:
- On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
If you are using Windows 8 or Windows 8.1:
- Hold down the Windows key, press the letter X, and then click Control Panel.
- Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
If you are using Windows Server 2008 or Windows Server 2008 R2:
- On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
If you are using Windows Vista or Windows 7:
- On the taskbar, click Start, and then click Control Panel.
- Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
In the Connections pane, go to the connection, site, application, or directory for which you want to configure page output caching.
In the Home pane, scroll to Output Caching, and then double-click Output Caching.
In the Actions pane, click Add...
In the Add Cache Rule dialog box, type the file name extension you want to cache in the File name extension box, and then select the User-mode caching option, the Kernel-mode caching option, or both.
Select the options that you want to use for caching, and then click OK.
None.
Element | Description |
---|---|
add |
Optional element. Adds an output caching profile to the collection of output caching profiles. |
clear |
Optional element. Removes all references to output caching profiles from the output caching profile collection. |
remove |
Optional element. Removes a reference to an output caching profile from the output caching profile collection. |
The following configuration example enables user-mode caching and kernel-mode caching, both of which are enabled by default in IIS 7.0. It also uses the <add>
element contained by the <profiles>
element to enable output caching for files with the .asp file name extension. It also uses the policy attribute to output cache the page until it changes; it does the same for kernel caching using the kernelCachePolicy attribute.
<configuration>
<system.webServer>
<caching enabled="true" enableKernelCache="true">
<profiles>
<add extension=".asp" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" />
</profiles>
</caching>
</system.webServer>
</configuration>
The following code example sets the maximum output cache size to 1 gigabyte and sets the maximum size of a response that can be stored in the output cache to 512 kilobytes.
<configuration>
<system.webServer>
<caching enabled="true" enableKernelCache="true" maxCacheSize="1000" maxResponseSize="512000"/>
</system.webServer>
</configuration>
The following examples configure page output caching for files with the .asp file name extension, and configure IIS to cache in user mode and kernel mode until ASP files change.
appcmd.exe set config -section:system.webServer/caching /+"profiles.[extension='asp',policy='CacheUntilChange',kernelCachePolicy='CacheUntilChange']" /commit:apphost
Note
You must be sure to set the commit parameter to apphost
when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample {
private static void Main() {
using(ServerManager serverManager = new ServerManager()) {
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection cachingSection = config.GetSection("system.webServer/caching");
ConfigurationElementCollection profilesCollection = cachingSection.GetCollection("profiles");
ConfigurationElement addElement = profilesCollection.CreateElement("add");
addElement["extension"] = @"asp";
addElement["policy"] = @"CacheUntilChange";
addElement["kernelCachePolicy"] = @"CacheUntilChange";
profilesCollection.AddAt(0, addElement);
serverManager.CommitChanges();
}
}
}
Imports System
Imports System.Text
Imports Microsoft.Web.Administration
Module Sample
Sub Main()
Dim serverManager As ServerManager = New ServerManager
Dim config As Configuration = serverManager.GetApplicationHostConfiguration
Dim cachingSection As ConfigurationSection = config.GetSection("system.webServer/caching")
Dim profilesCollection As ConfigurationElementCollection = cachingSection.GetCollection("profiles")
Dim addElement As ConfigurationElement = profilesCollection.CreateElement("add")
addElement("extension") = "asp"
addElement("policy") = "CacheUntilChange"
addElement("kernelCachePolicy") = "CacheUntilChange"
profilesCollection.AddAt(0, addElement)
serverManager.CommitChanges()
End Sub
End Module
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var cachingSection = adminManager.GetAdminSection("system.webServer/caching", "MACHINE/WEBROOT/APPHOST");
var profilesCollection = cachingSection.ChildElements.Item("profiles").Collection;
var addElement = profilesCollection.CreateNewElement("add");
addElement.Properties.Item("extension").Value = "asp";
addElement.Properties.Item("policy").Value = "CacheUntilChange";
addElement.Properties.Item("kernelCachePolicy").Value = "CacheUntilChange";
profilesCollection.AddElement(addElement, 0);
adminManager.CommitChanges();
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set cachingSection = adminManager.GetAdminSection("system.webServer/caching", "MACHINE/WEBROOT/APPHOST")
Set profilesCollection = cachingSection.ChildElements.Item("profiles").Collection
Set addElement = profilesCollection.CreateNewElement("add")
addElement.Properties.Item("extension").Value = "asp"
addElement.Properties.Item("policy").Value = "CacheUntilChange"
addElement.Properties.Item("kernelCachePolicy").Value = "CacheUntilChange"
profilesCollection.AddElement addElement, 0
adminManager.CommitChanges()