CacheAdapter 2.4 – Bug fixes and minor functional update

Posted by Glav on ASP.net Weblogs See other posts from ASP.net Weblogs or by Glav
Published on Wed, 28 Mar 2012 20:22:54 GMT Indexed on 2012/03/29 23:30 UTC
Read the original article Hit count: 354

Note: If you are unfamiliar with the CacheAdapter library and what it does, you can read all about its awesome ability to utilise memory, Asp.Net Web, Windows Azure AppFabric and memcached caching implementations via a single unified, simple to use API from here and here..

The CacheAdapter library is receiving an update to version 2.4 and is currently available on Nuget here.

Update: The CacheAdapter has actualy just had a minor revision to 2.4.1. This significantly increases the performance and reliability in memcached scenario under more extreme loads. General to moderate usage wont see any noticeable difference though.

Bugs

This latest version fixes a big that is only present in the memcached implementation and is only seen in rare, intermittent times (making i particularly hard to find). The bug is where a cache node would be removed from the farm when errors in deserialization of cached objects would occur due to serialised data not being read from the stream in entirety.

The code also contains enhancements to better surface serialization exceptions to aid in the debugging process. This is also specifically targeted at the memcached implementation. This is important when moving from something like memory or Asp.Web caching mechanisms to memcached where the serialization rules are not as lenient.

There are a few other minor bug fixes, code cleanup and a little refactoring.

Minor feature addition

In addition to this bug fix, many people have asked for a single setting to either enable or disable the cache.In this version, you can disable the cache by setting the IsCacheEnabled flag to false in the application configuration file. Something like the example below:

  <Glav.CacheAdapter.MainConfig>
    <setting name="CacheToUse" serializeAs="String">
      <value>memcached</value>
    </setting>
    <setting name="DistributedCacheServers" serializeAs="String">
      <value>localhost:11211</value>
    </setting>
    <setting name="IsCacheEnabled" serializeAs="String">
      <value>False</value>
    </setting>
  </Glav.CacheAdapter.MainConfig>

Your reasons to use this feature may vary (perhaps some performance testing or problem diagnosis). At any rate, disabling the cache will cause every attempt to retrieve data from the cache, resulting in a cache miss and returning null. If you are using the ICacheProvider with the delegate/Func<T> syntax to populate the cache, this delegate method will get executed every single time. For example, when the cache is disabled, the following delegate/Func<T> code will be executed every time:

var data1 = cacheProvider.Get<SomeData>("cache-key", DateTime.Now.AddHours(1), () =>
{
    // With the cache disabled, this data access code is executed every attempt to
    // get this data via the CacheProvider.
    var someData = new SomeData() { SomeText = "cache example1", SomeNumber = 1 };
    return someData;
});

One final note: If you access the cache directly via the ICache instance, instead of the higher level ICacheProvider API, you bypass this setting and still access the underlying cache implementation. Only the ICacheProvider instance observes the IsCacheEnabled setting.

Thanks to those individuals who have used this library and provided feedback. Ifyou have any suggestions or ideas, please submit them to the issue register on bitbucket (which is where you can grab all the source code from too)

© ASP.net Weblogs or respective owner

Related posts about .NET

Related posts about ASP.NET