Jaa


Enable Windows Server AppFabric Local Cache (XML)

Windows Server AppFabric 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 Windows Server AppFabric 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 (Windows Server AppFabric 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 (Windows Server AppFabric 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 Windows Server AppFabric 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 (Windows Server AppFabric 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 (Windows Server AppFabric 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 Windows Server AppFabric Caching Physical Architecture Diagram. You can determine which hosts are lead hosts by using the Windows PowerShell administration tool. For more information about Windows PowerShell, see Using Windows PowerShell to Manage Windows Server AppFabric Caching Features.

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

Get Started with a Windows Server AppFabric Cache Client (XML)
Configuring an ASP.NET Session State Provider (Windows Server AppFabric Caching)
Cache Clients and Local Cache (Windows Server AppFabric Caching)
Using Configuration Methods (Windows Server AppFabric Caching)
Windows Server AppFabric Caching Concepts
Developing a Cache Client (Windows Server AppFabric Caching)