DCSIMG
Quick Tip – How to Enable Local Cache in Velocity (Microsoft Distributed Cache) Client - Gil Fink's Blog

Gil Fink's Blog

Fink about IT

News

Microsoft MVP

My Facebook Profile My Twitter Profile My Linkedin Profile

Locations of visitors to this page

Creative Commons License

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2013 Gil Fink

Hebrew Articles

Index Pages

My OSS Projects

English Articles

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

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">
      <hosts>    
        <host name="localhost"
              cachePort="22233"
              cacheHostName="DistributedCacheService" />
      </hosts>
    </dcacheClient> 

Summary

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

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# July 16, 2009 2:09 PM

Quick Tip ??? How to Enable Local Cache in Velocity (Microsoft … | Xmas Tips said:

Pingback from  Quick Tip ??? How to Enable Local Cache in Velocity (Microsoft &#8230;&nbsp;|&nbsp;Xmas Tips

# July 16, 2009 9:42 PM

lt32s said:

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?

# September 9, 2009 1:05 AM

Gil Fink said:

@It32s,

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.

# September 9, 2009 10:10 AM

lt32s said:

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.

thanks

# September 9, 2009 11:04 PM

Gil Fink said:

@It32s,

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.

# September 10, 2009 8:07 AM