Quick Tip – How to Enable Local Cache in Velocity (Microsoft Distributed Cache) Client

July 16, 2009

Quick Tip – How to Enable Local Cache in Velocity (Microsoft Distributed Cache) Client

Since I got this question twice .Net Framework New Logo
this week, I’m writing this post.
One of Velocity (Microsoft
Distributed Cache)
features is
called local cache. In this post I’ll
show how to enable that feature.

Velocity Client Local Cache

Local cache is a Velocity feature that can help speed up access on Velocity clients.
When enabled, a de-serialized copy of the object is saved in the client memory.
Before retrieving cached objects, the client cache will first checks whether the
object exists locally and if so will get it from the local cache.

Enabling Local Cache

There are two ways to enable local cache on a Velocity client:

  • The runtime way – the DataCacheFactory object has a constructor that gets
    as parameter whether the local cache is enabled.
    for example:
    DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
    servers[0] = new DataCacheServerEndpoint("localhost",
                            22233, "DistributedCacheService");
    bool routingClient = false;
    // True = Enable local cache
    // False = Disable local cache
    bool localCache = false;
    var factory = new DataCacheFactory(servers,
        routingClient, localCache);
    var cache = factory.GetCache("default");

  • The configuration way – in the client config file, we we use the localCache

    attribute like in the following example:

    <dcacheClient deployment="simple" localCache="false">
        <host name="localhost"
              cacheHostName="DistributedCacheService" />


Local cache is a very useful feature of Velocity. It can help to boost the

performance of an application that uses Velocity to new heights.

DotNetKicks Image
Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



  1. lt32sSeptember 9, 2009 ב 1:05

    If you opt to use local cache, is there a mechanism to keep the local cache in sync with the server cache so that the local cache does not become invalidated?

  2. Gil FinkSeptember 9, 2009 ב 10:10


    When using local cache in Velocity you can choose the policy of synchronization. You have syncPolicy attribute which uses the DataCacheLocalCacheSyncPolicy enumeration to choose how locally cached objects are invalidated. This can be by using timeouts or notifications.

  3. lt32sSeptember 9, 2009 ב 23:04

    Do you know what the future of Velocity is? Is it going to be a commercial product, free download, included in .NET 4.0?

    Were currently looking into Velocity for our project but were running VS 2010 and .NET 4.0 so were unable to use it at this time.

    Was just curious to see if you had any additional information.


  4. Gil FinkSeptember 10, 2009 ב 8:07

    Currently, Velocity is suppose to be a free download when it will be realesed. This is what was said in the last PDC conference and since then I didn’t hear otherwise.