Wednesday, July 23, 2008

Microsoft Distributed Cache

I recently downloaded and had a look at Velocity aka Microsoft Distributed Cache. The team released CTP 1 in early July so it will be interesting to see how Velocity develops over the coming months. The basic idea is to provide a general purpose, distributed, in-memory cache. The cache is provided in the form of a cluster with load balancing behind the scenes. The below diagram helps to explain.

VelocityDiagram

The cache cluster includes a configurable number of cache hosts, each running as a Windows Service. The cluster requires a network share to distribute configuration data including the eviction and expiration policy. Velocity includes a console application to administer the cache.

Velocity doesn't include disk persistence so if the cluster goes down, the cache is reset. You can however attach metadata tags to cache items. This makes it really easy to retrieve groups of objects based on matching metadata.

Working with the cache is pretty straight forward from a .NET application. The Velocity install includes client API with the usual CRUD operations. Here's an example of adding a string to the cache.

using System.Data.Caching;

CacheFactory CacheCluster1 = new CacheFactory();
Cache Cache1 = CacheCluster1.GetCache("Cache1");

Cache1.Add("cachedStringKey1","This string will be stored in cache");

Velocity is targeted at clustered web environments where you can gain some performance benefits by having clustered in-memory state. The Velocity team have also provided a SessionStateStoreProvider that allows you to use it for managing your session state. Here's an article that explains how to configure your ASP.NET application to use Velocity for custom session state. One can only assume that Velocity will become a part of IIS in a future release?


1 comment:

  1. Although Velocity has made progress from CTP1 to CTP2, it still leaves much to be desired. It will be some time before they provide all the important features in a distributed cache and even longer before it is tested in the market. I wish them good luck. In the meantime, NCache already provides all CTP2 & V1, and many more features. NCache is the first, the most mature, and the most feature-rich distributed cache in the .NET space. NCache is an enterprise level in-memory distributed cache for .NET and also provides a distributed ASP.NET Session State. Check it out at Distributed Cache. NCache Express is a totally free version of NCache. Check it out at Free Distributed Cache.

    ReplyDelete