How to: Get Started with a Simple Client (Code) (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 the cache client programmatically or with an application configuration file. The following procedures describe how to programmatically configure a simple client for your application. For information about how to do this with an application configuration file, see How to: Get Started with a Simple Client (XML) (Velocity).
When you programmatically configure your cache client, the configuration settings are passed to the DataCacheFactory class constructor.
For performance reasons, we recommend that you minimize the number of DataCacheFactory objects created in a cache-enabled application. Store the DataCacheFactory object in a variable available to all parts of the application that use cache clients.
The cache client type is defined by the
routingClient parameter in the DataCacheFactory class constructor. For a simple client, the
routingClient parameter must be
false. 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)
To configure a simple client programmatically
Create an array of DataCacheServerEndpoint objects to specify the cache hosts for the client.
Configure your cache hosts by assigning the cache host array from the previous step to the
serversparameter of the DataCacheFactory constructor.
Select a simple client type by assigning a
falsevalue to the
routingClientparameter of the DataCacheFactory constructor.
Configure local cache by assigning a
falsevalue to the
localCacheparameter of the DataCacheFactory constructor. Use the
truevalue to enable local cache or a
falsevalue to disable local cache.
Use the GetCache method to obtain an instance of the routing client.
This example shows the programmatic configuration of a simple client for a cache called
NamedCache1. This simple client has local cache disabled, and is configured to point to a cache server that is named
CacheServer2. Replace the server properties in this example with those of your cache server(s). Add additional DataCacheServerEndpoint objects to the
servers array for each of the other cache hosts in the cluster.
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).
servers array is created. This example configures a cache host that is named
'declare array for cache host(s) Dim servers(0) As DataCacheServerEndpoint 'specify cache host(s) servers(0) = New DataCacheServerEndpoint("CacheServer2", _ 22233, "DistributedCacheService")
//declare array for cache host(s) DataCacheServerEndpoint servers = new DataCacheServerEndpoint; //specify cache host(s) servers = new DataCacheServerEndpoint("CacheServer2", 22233, "DistributedCacheService");
Next, pass the configuration parameters to the DataCacheFactory class constructor and instantiate the cache client that has the GetCache method. This example creates a cache client for a cache that is named
'configure simple client with local cache disabled Dim mySimpleCacheFactory As DataCacheFactory _ = New DataCacheFactory(servers, False, False) 'get cache client for cache "NamedCache1" Dim mySimpleCacheClient As DataCache _ = mySimpleCacheFactory.GetCache("NamedCache1")
//configure simple client with local cache disabled DataCacheFactory mySimpleCacheFactory = new DataCacheFactory(servers, false, false); //get cache client for cache "NamedCache1" DataCache mySimpleCacheClient = mySimpleCacheFactory.GetCache("NamedCache1");