Why Clydesdale?
Expertise
Strategic Partners
Blog
Contact
Home
Clydesdale Software Logo

Clydesdale Software, Inc.

355 South Teller St.

Suite 200

Lakewood, CO 80226

info@ClydesdaleSoftware.com


Follow Us: Twitter RSS



Go Back

Azure Cache: DataCacheException –SOLVED!

I have found a simple solution to the azure caching issue.  First off the error of  SubStatus<ES0006> which is throttled is not true.  The real issue is stale connections (I think).  When the cache is not used for a bit the connections go stale, then when you try to use them they throw the throttled exception again and again and it seems to take some time for it to stop being used and a new one created. 

The solution/work around is to try and get the cache item once and if it fails recreated the cache object then go for the cache object.  Before I put this in place I got hundreds of errors.

The code:

Instead to using the DataCache’s GetCacheItem use this one.

private static DataCacheItem GetCacheItem(string key)

        {

            try

            {

                //See if the cache connections are valid

                return DataCache.GetCacheItem(key);

            }

            catch

            {

                //This is an attempt to get fresh connections everytime

                InitCache();

            }

            return DataCache.GetCacheItem(key);

        }

And the InitCache:

private static void InitCache()

        {

            lock (lockObject)

            {

                var cacheFactory = new DataCacheFactory();

                var cache = cacheFactory.GetDefaultCache();

                instance = cache;

            }

        }

Instance and lockObject are fields:

private static DataCache instance;

private static readonly Object lockObject = new object();

And for other cache operation such as puts I have this property:

private static DataCache DataCache

        {

            get

            {

                if (instance == null)

                {

                    InitCache();

                }

                return instance;

            }

        }

The Result

Now no emails about this error and throughput has increased because only the first request fails with the cache then recreates the cache object and everything runs smoothly.

Facebook Twitter DZone It! Digg It! StumbleUpon Technorati Del.icio.us NewsVine Reddit Blinklist Add diigo bookmark