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
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).
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 (AppFabric 1.1 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 (AppFabric 1.1 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 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