How to: Configure Windows Azure Caching
You can set many aspects of Windows Azure Caching from Visual Studio. For more advanced configuration, see Advanced Caching Configuration.
Caching must first be available on a role. To add caching to a role, see How to: Use Windows Azure Caching. You can also create a worker role that’s entirely dedicated to caching. If you have a role that supports caching, you can configure the cache's behavior by using the settings on the Caching tab of the role's property pages. To open the Caching tab, expand the Roles folder in your Windows Azure project, open the shortcut menu for the role that you want to configure, choose Properties, and then choose the Caching tab.
You use the Service Configuration list to specify whether the caching setting applies to the Local, Cloud, or other service configuration. Caching is emulated when you run a Windows Azure application locally. You can configure some properties when this field is set to All Configurations, but you can only modify the named caches section when the field is set to a specific configuration.
If you want to use caching, make sure that the Enable Caching check box is selected.
In the Cache cluster settings section, you can specify whether this role is entirely dedicated to the cache or the cache is co-located and shares virtual machine resources with the program space for this role. If you created this role by using the role template for a dedicated cache workers, this option is set to Dedicated. If you added caching to an existing role, this option is set to Co-located. For co-located configurations, you can also set the percentage of the memory resources that are allocated to the current role that you want to make available to the cache service. The percentage applies to all instances of the role. The total available cache size includes cache space that each instance of a role contributes.
You should test your application to determine what its memory requirements are and make sure that the percentage that you choose leaves enough memory for the application to run efficiently. The percentage is based on the total amount of memory that’s available to the virtual machine, the size of which is set in the Configuration tab. The actual memory that’s available for each virtual machine size is listed in How To: Configure Virtual Machine Sizes. Visual Studio checks the values that you specify and displays a warning if the percentage of memory that’s allocated to the cache is outside the recommended range for your virtual machine size.
You can test your application's memory usage most easily by logging into the virtual machine as Using Remote Desktop with Windows Azure Roles describes. As you produce or simulate the amount of usage that you expect for your application, start Task Manager, and then look in the status bar to find out how much physical memory the application uses. A good value to use for the cache percentage would be 100 minus either this value or slightly less to accommodate additional usage.
Also in the Cache cluster settings section, you can specify what storage account you want the caching service to use to manage its own runtime state. You can use the storage emulator (indicated by UseDevelopmentStorage=true) to run in the compute emulator, but you must specify valid credentials to ensure that the cache runs correctly after you deploy your application to Windows Azure. To supply these credentials, you either allow Visual Studio to substitute the credentials with publish settings or explicitly provide the credentials for the Cloud configuration. To change this setting, choose the ... button on the right side of the Select Configuration text box. You can then specify these settings in the Storage Account Connection String dialog box.
The Named Cache Settings section contains settings that apply to named caches. Different caches may use different settings. To acquire a handle to a cache in code, you supply this name to the cache factory when you request a cache. In configuration files, you can reference this cache by using the cacheName attribute of a provider. By creating named caches for specific uses, you can keep data with different policies and requirements in the same cache cluster. The following table describes these settings.
The name of the named cache. This name must contain fewer than 256 characters, and each character must be an alphanumeric character, a hyphen, or an underscore.
The number of additional copies of the cache that are maintained on different instances of the role. The only valid values are 0 and 1.
A value that specifies whether notifications are raised, through callbacks, for certain cache operations. For more information, see Cache Notifications.
The policy for deleting data when the cache approaches capacity. Valid values are None and Least Recently Used (LRU). If set to None, objects aren’t deleted from the cache unless they’ve expired. If the cache runs out of capacity, an exception is thrown.
Time to live (min)
The amount of time (in minutes) before an object is removed from the cache. The Expiration Type setting determines how this time is interpreted.
The behavior of the timer that determines when objects expire. If this setting is set to Absolute, a fixed amount of time is allotted for an object before it expires. If this setting is set to Sliding Window, the expiration timer is reset every time the object is accessed, so that objects expire only if they haven’t been used for a specified amount of time.
The settings on this tab are reflected in the service configuration file. You can also edit the service configuration file manually or by using the Settings tab. For information about how to configure the cache settings manually, see Configuring Caching on Windows Azure Roles.