How to: Enable Local Cache (XML) (Velocity)
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]
Microsoft project code named "Velocity" 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 How to: Enable Local Cache (Code) (Velocity).
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 (Velocity).
These procedures assume that you have already prepared your development environment and set references to the "Velocity" assemblies, and so on. For more information, see How to: Prepare the Development Environment (Velocity).
Data in the cache is not encrypted and is available to any cache client with the appropriate configuration settings. We highly recommend that you secure the XML-based application configuration files used to specify the cache client.
To enable local cache with an application configuration file
Create the application configuration file and configure the cache client as a routing or simple client. For more information see How to: Get Started with a Routing Client (XML) (Velocity) or How to: Get Started with a Simple Client (XML) (Velocity).
localCacheelement as a child of the
isEnabledattribute of the
localCacheelement equal to
trueto enable the local cache.
syncattribute in the
localCacheelement. Set this attribute to
TTLBasedto use a time-out for invalidating the local cache. Use
NotificationBasedto use cache notifications for invalidating the local cache. The
NotificationsBasedoption requires that you enable cache notifications on the named cache. For more information, see Cache Notifications (Velocity).
ttlValueattribute in the
localCacheelement 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 (Velocity).
(optional) Set the
objectCountattribute in the
localCacheelement to specify the maximum number of locally cached objects. The default value is 100,000 objects. This threshold triggers when the cache client begins evicting 20% of the least recently used locally cached objects.
(optional) 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
clientNotificationselement as a child of the
dataCacheClientelement. Use the
pollIntervalattribute of the
clientNotificationselement to specify the specify poll interval value. This element and attribute can be used to specify a specify poll interval for cache notifications even if you do not want to use local cache.
This example shows how the local cache element looks when local cache is enabled. This element should be added inside the
<!-- local cache enabled --> <localCache isEnabled="true" sync="TTLBased" 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 those of 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 the Physical Model section in General Concept Models (Velocity). You can determine which hosts are lead hosts by using the PowerShell administration tool. For more information about PowerShell, see Cache Administration with PowerShell (Velocity).
Visual Basic may at first automatically add elements to your application's configuration file. These additional elements are not required by "Velocity" and may be deleted if you do not otherwise need them for your application.
<?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.Data.Caching.DataCacheClientSection, CacheBaseLibrary" allowLocation="true" allowDefinition="Everywhere"/> <!-- required to read the <fabric> element, when present --> <section name="fabric" type="System.Data.Fabric.Common.ConfigFile, FabricCommon" allowLocation="true" allowDefinition="Everywhere"/> </configSections> <!-- routing client--> <dataCacheClient deployment="routing"> <!-- local cache enabled --> <localCache isEnabled="true" sync="TTLBased" objectCount="100000" ttlValue="300" /> <!--(optional) specify cache notifications poll interval <clientNotification pollInterval="300" /> --> <!-- cache host(s) --> <hosts> <host name="CacheServer1" cachePort="22233" cacheHostName="DistributedCacheService"/> </hosts> </dataCacheClient> </configuration>
How to: Get Started with a Simple Client (XML) (Velocity)
How to: Get Started with a Routing Client (XML) (Velocity)
How to: Configure a Session State Provider (XML) (Velocity)
How to: Set Log Sink Levels (XML) (Velocity)