Enable Local Cache (XML)

Microsoft AppFabric 1.1 for Windows Server offers the option to configure a cache client programmatically or with an application configuration file. The procedures in this topic describe how to enable local cache on your cache client when you use an XML-based application configuration file. For information about how to do this programmatically, see Enable AppFabric 1.1 Local Cache.

In the application configuration file, the local cache settings are defined in the localCache element, a child of the dataCacheClient element. The isEnabled attribute in the localCache element determines whether local cache is enabled or not. Alternatively, the localCache element may be missing (or commented out) to indicate that it is disabled. For more information about the application configuration settings, see Application Configuration Settings (AppFabric 1.1 Caching).

These procedures assume that you have already prepared your development environment and set references to the AppFabric Caching assemblies, and so on. For more information, see Preparing the Cache Client Development Environment (AppFabric 1.1 Caching).

To enable local cache with an application configuration file

  1. Create the application configuration file, named App.config, and add it to your project. For more information see Get Started with a Cache Client (XML).

  2. Add the localCache element as a child of the dataCacheClient element.

  3. Set the isEnabled attribute of the localCache element equal to true to enable the local cache.

  4. Set the sync attribute in the localCache element. Set this attribute to TimeoutBased to use a time-out for invalidating the local cache. Use NotificationBased to additionally use cache notifications for invalidating the local cache. The NotificationsBased option requires that you enable cache notifications on the named cache. For more information, see Cache Notifications (AppFabric 1.1 Caching).

  5. Set the ttlValue attribute in the localCache element equal to the desired number of seconds that objects should remain in the local cache. 300 seconds is the default value. For more information, see Expiration and Eviction (AppFabric 1.1 Caching).

  6. Optionally, set the objectCount attribute in the localCache element to specify the maximum number of locally cached objects. The default value is 10,000 objects. This threshold triggers the cache client to begin evicting 20 percent of the least recently used locally cached objects.

  7. Optionally, if you are using cache notifications and want to specify a poll interval that is different than the default value of 300 seconds, add the clientNotification element as a child of the dataCacheClient element. Use the pollInterval attribute of the clientNotification element to specify the specify poll interval value. This element and attribute can be used to specify a poll interval for cache notifications even if you do not want to use local cache.

Example

This example shows how the local cache element looks when local cache is enabled. This element should be added inside the dataCacheClient element.

XML

<!-- local cache enabled -->
<localCache
  isEnabled="true"
  sync="TimeoutBased"
  objectCount="100000"
  ttlValue="300" />

This example application configuration file has local cache enabled and is configured to point to one cache server, CacheServer1. To use this example, replace the server name in this example with your cache server's name. Add or remove host tags as necessary to suit your environment.

Ideally, specify those cache hosts that have been designated as lead hosts. Lead hosts are usually the first cache servers installed in the cluster. For more information about lead hosts, see AppFabric Caching Physical Architecture Diagram (AppFabric 1.1 Caching). You can determine which hosts are lead hosts by using the Windows PowerShell administration tool. For more information about Windows PowerShell, see Cache Administration with Windows PowerShell (AppFabric 1.1).

Note

Visual Basic may at first automatically add elements to your application's configuration file. These additional elements are not required by the caching features of AppFabric and may be deleted if you do not otherwise need them for your application.

XML

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

   <dataCacheClient>
      <!-- (optional) specify local cache -->
      <localCache
         isEnabled="true"
         sync="TimeoutBased"
         objectCount="100000"
         ttlValue="300" />

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

      <hosts>
         <host
            name="CacheServer1"
            cachePort="22233"/>
      </hosts>
   </dataCacheClient>
</configuration>

See Also

Concepts

AppFabric Caching Concepts (AppFabric 1.1 Caching)

  2012-09-12