Application Configuration Settings (Windows Server AppFabric Caching)
With the caching features of Windows Server AppFabric, you may configure your application's cache client settings programmatically, by using an application configuration file, or by using both approaches at different places in your application. For more information about each of these configuration methods and how to select each, see Client Configuration Options (Windows Server AppFabric Caching).
Regardless of the approach you take, you are configuring the same cache client setting. The tables in this topic present the settings available to the cache client and show how they are configured in the XML-based application configuration file and programmatically, by using code.
For more information about how to use these settings in your application, see the examples covered in XML-Based Client Configuration (Windows Server AppFabric Caching).
Cache Client Setting
Setting | XML Configuration Location | Code Configuration Location |
---|---|---|
Client time-out (milliseconds) |
The |
The RequestTimeout property of the DataCacheFactoryConfiguration class. |
Channel open time-out (milliseconds) |
The |
The ChannelOpenTimeout property of the DataCacheFactoryConfigurationc class. |
Maximum number of connections to the server |
The |
The MaxConnectionsToServer property of the DataCacheFactoryConfiguration class. |
Cache Host Settings
For each cache client, you must specify one or more cache hosts in the cluster. Specify lead hosts because cache hosts designated as lead hosts help manage the cluster. Initially, lead hosts are the first cache hosts installed in the cluster. For more information about lead hosts, see Windows Server AppFabric Caching Physical Architecture Diagram.
In the application configuration file, the settings for each cache host are specified in a host element, a child of the hosts
element. Programmatically, each host is defined in the class constructor of the DataCacheServerEndpoint class. After they are instantiated, those DataCacheServerEndPoint objects are then passed to the Servers property of the DataCacheServerEndpoint class.
Setting | XML Configuration Location | Code Configuration Location |
---|---|---|
Cache server name |
The |
The HostName property of the DataCacheServerEndpoint class. |
Cache port number |
The |
The CachePort property of the DataCacheServerEndpoint class. |
Local Cache Settings
The local cache settings specify whether local cache should be enabled, the way locally cached objects should be invalidated, the object time-out, and whether cache notifications should be used to invalidate locally cached objects.
In the application configuration file, local cache settings are defined in the localCache
element, a child of the dataCacheClient
element. Programmatically, local cache is configured with an instance of the DataCacheFactoryConfiguration class that is passed to the constructor of the DataCacheFactory class constructor. For more information about local cache, see Cache Clients and Local Cache (Windows Server AppFabric Caching).
Setting | XML Configuration Location | Code Configuration Location |
---|---|---|
Local cache enabled |
The |
The IsEnabled property of the DataCacheLocalCacheProperties class. This is then assigned to the LocalCacheProperties property of the DataCacheFactoryConfiguration class. |
Local cache invalidation method |
The |
The InvalidationPolicy property of the DataCacheLocalCacheProperties class. Possible values include NotificationBased and TimeoutBased. |
Local cache time-out (seconds) |
The |
The DefaultTimeout property of the DataCacheLocalCacheProperties class. |
Specific cache notifications poll interval (seconds) |
(optional) Specified by the |
The PollInterval property of the DataCacheNotificationProperties class. This is then assigned to the NotificationProperties property of the DataCacheFactoryConfiguration class. |
Maximum locally-cached object count |
(optional) Specified by the |
The ObjectCount property of the DataCacheLocalCacheProperties class. |
Note
For best performance, only enable local cache for objects that change infrequently. Using local cache for frequently changing data may increase the chance that the client will be working with stale objects. Although you could lower the ttlValue
and make a process refresh the local cache more frequently, the increased load on the cluster may outweigh the benefits of having the local cache. In such cases of frequently changing data, it is best to disable local cache and pull data directly from the cluster.
Notification Settings
In the application configuration file, notification properties are defined in the clientNotification
element, a child of the dataCacheClient
element. Programmatically, notification properties are configured with an instance of the DataCacheFactoryConfiguration class that is passed to the constructor of the DataCacheFactory class constructor. For more information, see Configuration Methods (Windows Server AppFabric Caching).
Setting | XML Configuration Location | Code Configuration Location |
---|---|---|
Specific cache notifications poll interval (seconds) |
Specified by the |
The PollInterval property of the DataCacheNotificationProperties class. This is then assigned to the NotificationProperties property of the DataCacheFactoryConfiguration class. |
Maximum queue length |
The |
The MaxQueueLength property of the DataCacheNotificationProperties class. |
Security Settings
In the application configuration file, security properties are defined in the securityProperties
element, a child of the dataCacheClient
element. Programmatically, security properties are configured with an instance of the DataCacheFactoryConfiguration class that is passed to the constructor of the DataCacheFactory class constructor. For more information, see Configuration Methods (Windows Server AppFabric Caching).
Setting | XML Configuration Location | Code Configuration Location |
---|---|---|
Mode |
The |
The SecurityMode property of the DataCacheSecurity class. Possible values include None and Transport. The DataCacheSecurity object is then assigned to the SecurityProperties property of the DataCacheFactoryConfiguration class. |
Protection level |
The |
The ProtectionLevel property of the DataCacheSecurity class. Possible values include None, Sign, and EncryptAndSign. |
Transport Settings
In the application configuration file, transport properties are defined in the transportProperties
element, a child of the dataCacheClient
element. Programmatically, transport properties are configured with an instance of the DataCacheFactoryConfiguration class that is passed to the constructor of the DataCacheFactory class constructor. For more information, see Configuration Methods (Windows Server AppFabric Caching).
Setting | XML Configuration Location | Code Configuration Location |
---|---|---|
Connection buffer size (bytes) |
The |
The ConnectionBufferSize property of the DataCacheTransportProperties class. This is then assigned to the TransportProperties property of the DataCacheFactoryConfiguration class. |
Maximum buffer pool size (bytes) |
The |
The MaxBufferPoolSize property of the DataCacheTransportProperties class. |
Maximum buffer size (bytes) |
The |
The MaxBufferSize property of the DataCacheTransportProperties class. |
Maximum output delay (milliseconds) |
The |
The MaxOutputDelay property of the DataCacheTransportProperties class. |
Channel initialization timeout (milliseconds) |
The |
The ChannelInitializationTimeout property of the DataCacheTransportProperties class. |
Receive timeout (milliseconds) |
The |
The ReceiveTimeout property of the DataCacheTransportProperties class. |
Example Application Configuration File
For the AppFabric assemblies to read the XML elements in the application configuration file, you must include the configSections
element as the first element in the file under the configuration
tag. Within the configSections
element, you must include one section
element associated with the dataCacheClient
element.
The following example shows an application configuration file that uses many of the cache client configuration options discussed in this topic. It is important to note that only the hosts
element is required in the dataCacheClient
to connect to the cluster. The other child elements all have default values.
<?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 requestTimeout="15000" channelOpenTimeout="3000" maxConnectionsToServer="1">
<localCache isEnabled="true" sync="TimeoutBased" ttlValue="300" objectCount="10000"/>
<clientNotification pollInterval="300" maxQueueLength="10000"/>
<hosts>
<host name="CacheServer1" cachePort="22233"/>
<host name="CacheServer2" cachePort="22233"/>
</hosts>
<securityProperties mode="Transport" protectionLevel="EncryptAndSign" />
<transportProperties connectionBufferSize="131072" maxBufferPoolSize="268435456"
maxBufferSize="8388608" maxOutputDelay="2" channelInitializationTimeout="60000"
receiveTimeout="600000"/>
</dataCacheClient>
</configuration>
See Also
Concepts
Client Configuration Options (Windows Server AppFabric Caching)
Cluster Configuration Settings (Windows Server AppFabric Caching)
Troubleshooting Windows Server AppFabric Caching
Using Windows PowerShell to Manage Windows Server AppFabric Caching Features
Windows Server AppFabric Caching Concepts
Developing a Cache Client (Windows Server AppFabric Caching)