Developing With Velocity - Phase II
In my limited testing environment I have decided to try only the basic sample of MS Velocity found in CTP2 Samples, and what I thought would be the most often used properties of Velocity.
By default, the Velocity's DistributedCache service after the installation is not running and is set to manual start, so to begin working with it you will need to launch it. This can be done using the admin PowerShell applet or by starting the Microsoft project code named “Velocity” Windows Service. I opted for using the PowerShell Administration tool. To use it double-click the icon of the admin tool and type in Start-CacheCluster. You must see a success message in the following form:
The service status column displaying word UP means the DistributedCache is running. If you have changed the default port then it is time to memorize it now before starting coding.
At this point one may want to review the settings of the Distributed Cache. To do so issue a Get-CacheConfig command and a window will populate with the basic configuration settings:
If you wondered what High/Low Watermark parameter means, it is a memory consumption threshold. This has to do with the eviction process of cached objects. Let's leave it out for now, but this is an interesting item to explore.
Now let's get our feet wet! To code against the DistributedCache one needs VS2008 and .NET 3.5 installed. Well, I would like to tell you right here that the CTP2 samples are not running out of the box with MS Velocity CTP3.
But do not get disappointed, I needed about 30 minutes to skim through the code and apply all the necessary changes to make the sample working. Besides, I can share my updated version of the SampleTest on demand with whoever does not wish spend time editing the code sample. The important thing that the help file accompanying CTP3 outlines all the changes between the two CTPs. This file is also very helpful in understanding the concepts behind and the base model of MS Velocity.
I guess any typical client app will require some preparations, so is in the sample, the first step is to configure the client.
We do it by defining the Cache Server Endpoint
DataCacheServerEndpoint servers = new DataCacheServerEndpoint;
// Parameter 1 = host name
// Parameter 2 = cache port number
// Parameter 3 = cache service name
servers = new DataCacheServerEndpoint("localhost", +
and create the cache factory
//Pass configuration settings to cacheFactory constructor
myCacheFactory = new DataCacheFactory(servers,false, true);
False is used here to specify that it is not a routing client and true is for using local cache.
The last step is to add the reference to the cache like that:
//Get reference to named cache called "NamedCache1"
myDefaultCache = myCacheFactory.GetCache("default");
Hooray, we are ready to run our sample tests!
The SampleTest CTP2 is a console application, but it is enough to provide one with enough information on the capabilities and get the sense of power the MS Velocity has to offer.
There is a number of tests that will be executed in a manner as displayed at the very top image. The code for the very first test looks like this:
I hope I encouraged you to explore Velocity further and do your own experiments.