When the cache cluster is configured, start the service named Microsoft Project code named "velocity" in Windows Services. This service will not be automatically started by default.
1. Set the volocityProgramCopy the set to the development machine. The Assembly is located in the velocity installation directory. The Assembly is as follows:
Cachebaselibrary. dll,
Clientlibrary. dll,
Fabriccommon. dll,
Casbase. dll.
2. Add the reference of the above assembly to the vs Project
3. Configure the xml configuration file of the cache client as the. config file, or directlyCodeSpecified configuration in
Select routing cleing or simple client, and select routing client to achieve the best performance.
Demo:
The following is a configuration example of a routing client. In this example, the local cache is not enabled, but two cache hosts are used: cacheserver1 and cacheserver2.
<? 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" > <! -- (Optional) specify local cache <localcache isenabled = "true" Sync = "ttlbased" objectcount = "100000" ttlvalue = "300"/> --> <! -- (Optional) specify cache restrictions poll interval <clientnotification pollinterval = "300"/> --> <! -- Cache host (s) --> < Hosts > < Host Name ="Cacheserver1" Cacheport = "22233" Cachehostname = "Distributedcacheservice" /> < Host Name = "Cacheserver2" Cacheport = "22233" Cachehostname ="Distributedcacheservice" /> </ Hosts > </ Datacacheclient > </ Configuration >
The following code demonstrates how to specify the configuration in the code.
// 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 Datachefactory mycachefactory = New Datacachefactory (servers, True , False );// Get cache client for cache "namedcache1" Datacache mydefaultcache = mycachefactory. getcache (" Namedcache1 ");