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
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).
Add the
localCache
element as a child of thedataCacheClient
element.Set the
isEnabled
attribute of thelocalCache
element equal totrue
to enable the local cache.Set the
sync
attribute in thelocalCache
element. Set this attribute toTimeoutBased
to use a time-out for invalidating the local cache. UseNotificationBased
to additionally use cache notifications for invalidating the local cache. TheNotificationsBased
option requires that you enable cache notifications on the named cache. For more information, see Cache Notifications (Windows Server AppFabric Caching).Set the
ttlValue
attribute in thelocalCache
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).Optionally, set the
objectCount
attribute in thelocalCache
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.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 thedataCacheClient
element. Use thepollInterval
attribute of theclientNotification
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)