Preparing the Cache Client Development Environment (Windows Server AppFabric Caching)

This topic describes how to prepare your Visual Studio project so that you can start developing cache-enabled applications. The following procedures assume that you have already installed Windows Server AppFabric and configured the AppFabric caching features on one or more cache servers, or on your development workstation. For more information, see Windows Server AppFabric Installation Guide (

In addition to installing AppFabric caching features, you must perform the following steps before the cache client can access the cache:

  • In Windows PowerShell, use the Use-CacheCluster to set the context to the target cache cluster.

  • Create any necessary named caches with the New-Cache command.

  • Grant access to the cache client's Windows account with the Grant-CacheAllowedClientAccount command.

  • Start the cache cluster with the Start-CacheCluster command.

For more information about using Windows PowerShell and the commands listed here, see Using Windows PowerShell to Manage Windows Server AppFabric Caching Features.

Preparing the Development Computer

To develop an application that uses the AppFabric caching features, the only setup requirement is to have the Cache Client feature of AppFabric installed. It is possible to develop on a cache host that has other AppFabric caching features installed, but the Cache Client feature is the only requirement on the development workstation.

Preparing the Visual Studio Project

The assemblies required for developing cache-enabled applications are installed to the global assembly cache (GAC). To develop a Visual Studio .NET application that uses these assemblies, you must reference them from your project.

To target the correct version of the .NET Framework

  1. Open your Visual Studio .NET project.

  2. In Solution Explorer, right-click the project name and then select Properties.

  3. Select the Application tab of the Project Properties dialog.

  4. Verify that the target framework version is .NET Framework 2.0 or higher.

    Do not use the client profile for the target framework version. In Visual Studio 2008, uncheck the Client-only Framework subset checkbox. In Visual Studio 2010, select .NET Framework versions that do not specify "Client Profile".

To add references to the AppFabric caching assemblies

  1. Open your Visual Studio .NET project.

  2. In Solution Explorer, right-click the project name and then select Add Reference.

  3. Select the Browse tab of the Add Reference dialog.

  4. Navigate to the .\Windows\System32\AppFabric directory.

    On 64-bit operating systems, the AppFabric directory will not be directly visible. To work around this problem, replace the System32 directory name with the name SysNative. This results in navigating to the C:\Windows\SysNative\AppFabric directory in this step.

  5. Add a reference to the following two assemblies: Microsoft.ApplicationServer.Caching.Client.dll and Microsoft.ApplicationServer.Caching.Core.dll.

  6. Optionally, add the using statement (Imports in Visual Basic) at the top of the code files to reference the Microsoft.ApplicationServer.Caching namespace.

To configure the cache client

  1. Determine the appropriate client settings for the client application. For more about the cache client types, see Cache Clients and Local Cache (Windows Server AppFabric Caching).

  2. Configure your cache client either programmatically or by using an application configuration file. For examples about how to do this, see Get Started with a Windows Server AppFabric Cache Client and Get Started with a Windows Server AppFabric Cache Client (XML).


The following is an example of a cache client configured by using an application configuration file. This example has local cache disabled and two cache hosts listed: CacheServer1 and CacheServer2. For more information, see Get Started with a Windows Server AppFabric Cache Client (XML).

<?xml version="1.0" encoding="utf-8" ?>
   <!--configSections must be the FIRST element -->
      <!-- required to read the <dataCacheClient> element -->
      <section name="dataCacheClient"
            Microsoft.ApplicationServer.Caching.Core, Version=, 
            Culture=neutral, PublicKeyToken=31bf3856ad364e35"

      <!-- (optional) specify local cache
         ttlValue="300" /> -->

      <!--(optional) specify cache notifications poll interval
      <clientNotification pollInterval="300" /> -->


The following is an example of how to configure a client programmatically. This example has the local cache disabled, lists only one cache server (CacheServer2), and creates a cache client for a cache named NamedCache1. For more information, see Get Started with a Windows Server AppFabric Cache Client.

// Declare array for cache host(s).
DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
servers[0] = new DataCacheServerEndpoint("CacheServer2", 22233);

// Setup the DataCacheFactory configuration.
DataCacheFactoryConfiguration factoryConfig = new DataCacheFactoryConfiguration();
factoryConfig.Servers = servers;

// Create a configured DataCacheFactory object.
DataCacheFactory mycacheFactory = new DataCacheFactory(factoryConfig);

// Get a cache client for the cache "NamedCache1".
DataCache myDefaultCache = mycacheFactory.GetCache("NamedCache1");

See Also