Eksportuj (0) Drukuj
Rozwiń wszystko
Ta zawartość nie jest dostępna w wymaganym języku. Wersja w języku angielskim znajduje się tutaj.

How to: Configure an Azure In-Role Cache

Updated: May 12, 2015

Caching can improve the performance of your cloud services by reducing the need for repeated computation of the same results. You can configure many aspects of an Azure In-Role Cache from Visual Studio. For more advanced configuration, see Advanced Caching Configuration.

Caching must first be available on a role. See How to: Use an Azure In-Role Cache in Azure Cloud Service for more information. 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 Azure cloud service 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 an Azure cloud service project 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 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 cloud service to determine its memory requirements and ensure that the percentage that you choose leaves enough memory for the cloud service 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 Virtual Machine and Cloud Service Sizes for Azure. 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 cloud service's memory usage most easily by logging into the virtual machine as Using Remote Desktop with Azure Roles describes. As you produce or simulate the amount of usage that you expect for your cloud service, start Task Manager, and then look in the status bar to find out how much physical memory the cloud service 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 provide valid credentials to ensure that the cache runs correctly after you deploy your cloud service to 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.


Name Description


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.

High Availability

When selected, makes a backup copy of the cache on another instance of the role.


A value that specifies whether notifications are raised, through callbacks, for certain cache operations. For more information, see Cache Notifications.

Eviction Policy

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.

Expiration Type

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 Azure Roles.

© 2015 Microsoft