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
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.