Programmatic Client Configuration (Velocity)

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

In Microsoft project code named "Velocity," you can specify the cache client configuration settings programmatically or with an XML configuration file. The programmatic approach is an excellent choice when you want to change settings programmatically or when you do not want an XML-based application configuration file. Then, if you make any changes to your cache client configuration, you may have to recompile the application. Changes to settings in an XML-based application configuration file do not require any recompilation. For more information about XML-based cache client configuration, see XML-Based Client Configuration (Velocity).

If you are using an XML application configuration file for client configuration with most of your application, you can override those settings programmatically. Setting configurations programmatically depends on whether you provide configuration parameters to the constructor of the DataCacheFactory class.

Cache Client Settings

When you configure the cache client programmatically, you must specify the same cache client settings as if you were using an application configuration file. The cache client settings configured are as follows:

  • Client Type: used to define whether the client should be routing or simple.

  • Local Cache: used to define whether local cache should be enabled and how long locally cached objects should be used before they are invalidated.

  • Hosts: used to define one or more lead hosts, which includes the server name, cache port number, and the name of the cache host service.

  • Log Sink Levels: used to define how cache client events should be traced, if at all.

Configuration Classes and Methods

The following classes are used to configure the cache client programmatically. For more information, see the following class library links.

  • DataCacheFactory class: To programmatically specify the cache client configuration settings, provide the settings that you want as parameters to the DataCacheFactory class constructor.

  • DataCacheServerEndPoint class: This class is used to define the cache host. An array of DataCacheServerEndPoint objects is passed to the DataCacheFactory constructor to configure the appropriate cache hosts. Specify the lead hosts in the cluster whenever possible.

  • DataCacheLogSink class: This class is used to define an individual log sink when you build a list of log sinks for the CreateLogSinks method. There are three types of log sinks: CONSOLE, ETW, or FILE. For more information about log sinks, see Log Sink Settings (Velocity).

  • CreateLogSinks method: This method is used to enable a list of log sinks after the DataCacheFactory object has been instantiated.

  • EnableAllAvailableSinks method: This method is available to use if you want to enable all log sinks.

  • DisableLogSinks method: This method is available to use if you want to disable all log sinks.

Process

The following example specifies a routing client that has local cache disabled and a cache host called CacheServer2. The cache client object is then created for the cache called NamedCache1.

'declare array for cache host(s)
Dim servers(0) As DataCacheServerEndpoint

'specify cache host(s)
servers(0) = New DataCacheServerEndpoint("CacheServer2", _
                            22233, "DistributedCacheService")

'specify cache client configuration
Dim mycacheFactory As DataCacheFactory _
    = New DataCacheFactory(servers, True, False)

'get cache client for cache "NamedCache1"
Dim myDefaultCache As DataCache
myDefaultCache = mycacheFactory.GetCache("NamedCache1")
//declare array for cache host(s)
DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];

//specify cache host(s)
servers[0] = new DataCacheServerEndpoint("CacheServer2", 
                        22233, "DistributedCacheService");

//specify cache client configuration
DataCacheFactory mycacheFactory 
    = new DataCacheFactory(servers, true, false);

//get cache client for cache "NamedCache1"
DataCache myDefaultCache = mycacheFactory.GetCache("NamedCache1");

See Also

Tasks

How to: Get Started with a Routing Client (Code) (Velocity)
How to: Enable Local Cache (Code) (Velocity)
How to: Set Log Sink Levels (Code) (Velocity)

Concepts

XML-Based Client Configuration (Velocity)
Cluster Configuration Storage Options (Velocity)
Troubleshooting (Velocity)
Cache Administration with PowerShell (Velocity)

Other Resources

Installation and Deployment (Velocity)
Configuration Settings (Velocity)
Programming Guide (Velocity)
Cache Concepts (Velocity)