How to: Configure a Cache Cluster for Azure In-Role Cache

Important

Microsoft recommends all new developments use Azure Redis Cache. For current documentation and guidance on choosing an Azure Cache offering, see Which Azure Cache offering is right for me?

An In-Role Cache cache cluster can be configured using the role property pages in Visual Studio. The cache size is determined by a combination of the virtual machine size, the instance count of the role, and the percentage of memory allocated to caching. This topic provides step by step guidance for enabling co-located caching on an existing role, and adding a dedicated cache worker role.

Note

Note that the cache sizes in this topic are approximate. For more details on configuring cache sizes and determining the cache cluster configuration settings that meet the needs of your application, see Capacity Planning Considerations for Azure In-Role Cache.

To create the Visual Studio solution and add the roles

  1. Start Visual Studio.

  2. Choose New, Project from the File menu.

  3. In the Installed Templates list, select Visual C#, Cloud (or Visual Basic, Could).

    Note

    Depending on which programming language is configured as the primary language in Visual Studio, the Visual C# or Visual Basic node may be under the Other Languages node in the Installed node.

    Ensure that one of the .NET Framework 4.x profiles is selected in the .NET Framework version drop-down list. Select Azure Cloud Service from the Cloud project type list. Type AzureCacheProject into the Name box and click OK.

  4. Select Worker Role from the .NET Framework 4 roles list and click the right arrow button to add it to the Azure solution.

  5. Click OK to add the worker role to the Azure solution.

    These two roles are used in the following two sections:

    • To configure a Cache Cluster using Co-located Role caching

    • To configure a Cache Cluster using Dedicated Role caching

To configure a Cache Cluster using Co-located Role caching

  1. Expand AzureCacheProject in Solution Explorer if it is not already expanded. Right-click WorkerRole1 under AzureCacheProject and choose Properties.

  2. Switch to the Configuration tab if it is not already selected. Set Instance count to 2, and keep the default VM size of Small.

    Role Instance Count and VM Size
    The amount of memory in a small virtual machine is 1.75 GB. Since there are two role instances configured, this means the total amount of memory across all instances is 3.5 GB.

  3. Switch to the Caching tab, and check the Enable Caching checkbox.

    Caching Role Properties
    The default settings are Co-located Role caching with a Cache Size (%) of 30%. These settings would provision a cache of approximately 1 GB.

    Note

    Note that the cache sizes in this topic are approximate. For more details on configuring cache sizes and determining the cache cluster configuration settings that meet the needs of your application, see Capacity Planning Considerations for Azure In-Role Cache.

To configure a Cache Cluster using Dedicated Role caching

  1. Expand AzureCacheProject in Solution Explorer if it is not already expanded.

    Right-click the Roles folder in the Azure project, and choose Add, New Worker Role Project, and choose Cache Worker Role. Keep the default name of CacheWorkerRole1, and click Add.

    Add Cache Worker Role

  2. Right-click CacheWorkerRole1 under AzureCacheProject and choose Properties.

  3. Switch to the Configuration tab if it is not already selected. Set Instance count to 2, and keep the default VM size of Small.

    Role Instance Count and VM Size

  4. Switch to the Caching tab.

    Cache Worker Role Properties
    Because this role is a Cache Worker Role, the Enable Caching checkbox is already checked and Dedicated Role caching is selected. When using Dedicated Role caching, the size of the cache is determined by multiplying the available virtual machine memory by the number of role instances. A very approximate amount of memory available for Dedicated Role caching for each virtual machine size is listed in the following table.

    Virtual Machine Size Available Memory for Caching

    Small

    Approximately 1 GB

    Medium

    Approximately 2.5 GB

    Large

    Approximately 5.5 GB

    Extra Large

    Approximately 11 GB

    The available memory for a small virtual machine size is approximately 1 GB, and because we have two role instances, the approximate cache size would be 2 MB.

    Note

    Note that the cache sizes in this topic are approximate. For more details on configuring cache sizes and determining the cache cluster configuration settings that meet the needs of your application, see Capacity Planning Considerations for Azure In-Role Cache.