Migrate from AppFabric Caching to 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?

This topic describes how to migrate from Microsoft AppFabric 1.1 for Windows Server to Microsoft Azure Cache. This type of caching migration might take place when you move an on-premises application to Azure.

AppFabric supports on-premises cache clusters the use your own servers and network infrastructure. The move to Azure is facilitated by the fact that most of the features and programming model of AppFabric are shared with Microsoft Azure Cache.

Plan for Migration

Before you migrate your cache-enabled application to the cloud, first review the differences between AppFabric and Microsoft Azure Cache. If you require a feature, such as write-through, that is not available in Microsoft Azure Cache, you must redesign that part of your solution in order to successfully move to Azure.

Analyze the AppFabric Cache Cluster

All of the caches and their relevant settings must be recreated on a cache-enabled Azure role. The first step is to analyze the AppFabric cache cluster to understand the current on-premises configuration.

  1. On the AppFabric cache cluster, open a Caching Administration Windows PowerShell command prompt.

  2. Run the Get-Cache command without any parameters. This lists the named caches.

  3. For each cache listed, run the Get-CacheConfig command. Pass the cache name as an argument to this command. Record the configuration settings for each cache. The following shows an example of this output.

    PS C:\Windows\system32> Get-CacheConfig TestCache
    
    CacheName                : TestCache
    TimeToLive               : 20 mins
    CacheType                : Partitioned
    Secondaries              : 0
    MinSecondaries           : 0
    IsExpirable              : True
    EvictionType             : None
    NotificationsEnabled     : True
    WriteBehindEnabled       : False
    WriteBehindInterval      : 300
    WriteBehindRetryInterval : 60
    WriteBehindRetryCount    : -1
    ReadThroughEnabled       : False
    ProviderType             :
    ProviderSettings         : {}
    
  4. Run the Get-CacheHost command to see a list of cache hosts in the cache cluster.

  5. For each cache host, run the Get-CacheHostConfig command. Pass the required arguments, the name of the cache host and the caching port (typically 22233). Record the Size parameter for each cache host.

  6. Add the Size values for all cache hosts to determine the overall size of the cache cluster.

Recreate the Cache Cluster in a Cloud Services Project

Warning

It is not supported to install both AppFabric and the Azure SDK on the same development machine. These steps assume that you are using separate machines or that you completely uninstall AppFabric before installating the Azure SDK.

In Visual Studio create a cloud service or open an existing cloud service. Add a Cache Worker Role to the cloud service. For more information, see Hosting Azure In-Role Cache on Dedicated Roles. This role will provide caching capabilities for the entire cloud service. The following steps describe how to recreate the named caches.

  1. In Visual Studio, go to the Solution Explorer window.

  2. In the Roles folder, double-click the role that hosts caching.

  3. In the role properties dialog, select the Caching tab.

  4. Under Named Cache Settings, first, modify the default cache to match the settings for the default cache in the AppFabric cache cluster. Then use the Add Name Cache link to add any additional caches required by your solution. The following screen shot shows several configured named caches.

    Caching Properties for Named Caches

  5. Use the to create or re-use a storage account. That account should be used in the storage account field on the Caching tab for deployments to the Cloud.

The following table correlates the output from Get-CacheConfig to the settings in the caching window.

Get-CacheConfig setting caching window setting

CacheName

Name

TimeToLive

Time to Live (min)

Secondaries (0, 1)

High Availability (0 = unselected, 1 = selected)

IsExpirable (True, False)

Expiration Type (True = Absolute, False = None)

EvictionType (None, LRU)

Evication Policy (None, LRU)

NotificationsEnabled (True, False)

Notifications (True = selected, False = unselected)

Note

Any AppFabric caching settings that are not listed here are not supported in Microsoft Azure Cache.

The cache cluster size can be configured by understanding the relationship between the virtual machine size and the number of running instances of this role. For more information, see Capacity Planning Considerations for Azure In-Role Cache.

Migrate Application Code

The final step is to move any application code to the cloud service projects. Note that the namespace and many of the APIs remain the same. The following steps provide migration guidance for each project that requires caching.

  1. In the Visual Studio project, first remove any references to the AppFabric assemblies.

  2. Next, backup the dataCacheClient sections of the web.config or app.config file.

  3. Remove the dataCacheClient and other caching sections from the web.config or app.config file.

  4. Next, prepare the project to use Microsoft Azure Cache. For more information, see How to: Prepare Visual Studio to Use Azure In-Role Cache.

  5. Then, manually add the removed dataCacheClient sections back into the web.config or app.config file. The following changes must be made to these sections:

    • Add an autoDiscover element to each section. The identifier attribute must reference the name of the role that hosts caching.

      <autoDiscover isEnabled="true" identifier="[cache cluster role name]" />
      
    • Remove all hosts, host, and securityProperties elements. These are unnecessary and unsupported in Microsoft Azure Cache.

See Also

Concepts

Migrate from Azure Shared Caching to In-Role Cache