Using AppPabric InProc Cache and Azure Together

First, a little background. I currently have a site hosted on Windows Azure with multiple instances and AppFabric as my only caching provider.

Everything was great until my traffic crashed this morning. After the instances rebooted and stopped responding, things turned out good again as soon as new instances started.

However, I started getting messages from AppFabric saying that I was being choked because there were too many requests for an hour. Fairly, it certainly gave him hell.

To avoid these messages in the future, I planned to implement InProc cache for a very short lifespan. So it checks the InProc first if not going to AppFabric, if not going to DB.

 ObjectCache cache = MemoryCache.Default;

 CacheItemPolicy policy = new CacheItemPolicy();
 policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(5);


The questions I have are

  • Is this the best way to handle the situation?
  • Will this interfere with AppFabric caching?
  • Any problems I'm overlooking?

Update I just wanted to say that I chose this method and it works well. I only used it for general data storage, not session state. Session State MemoryCache won't work too well on Azure due to lack of network proximity (as mentioned by David below).

Update 16-03-2012 Realizing the obvious, I also disabled SessionState on most of the pages. Most of my pages don't need this and hence it quickly reduces my cache calls under heavy load. I've also disabled ViewState for most of the pages, just for that slightly faster page load time.


source to share

5 answers

Try this:



Are you using a cache to store SessionState storage or shared data storage for your application, or both? This is not entirely clear because InProc usually refers to SessionState, but your example code does not look like SessionState.

Assuming you are storing data that can be safely cached locally, I would recommend looking into AppKabric Local Caching. This is basically what you want and does not require writing any separate code (I think ...).

Otherwise, using MemoryCache, as you outlined, is a workable scheme. I have done this in my apps, you just need to be careful to avoid cache inconsistency issues.

Depending on your application, you can also implement a cache for each request by storing the data in the HttpContext.Items collection. This is useful when different parts of the code can request the same data during the same request.



One thing I did was use HttpContext.Items. This is only for each query cache, but depending on the nature of your system it might be useful.



I would not suggest inproc due to the lack of server affinity.

One option for using the Windows Azure cache to avoid hourly quota throttling is to increase the cache size. Fortunately, the price doesn't scale linearly. For example: $ 45 for 128 MB, $ 55 for 256 MB. Thus, one option is to increase your cache to the next size. You will need to monitor the performance of the calculations, but through person counters, since there is no way to monitor the use of the cache in real time.

Another option is to bring your session state to SQL Azure, which is now the officially supported Azure 1.4 session state provider (August 2011 - see this article for more information). With the latest versions of SQL Azure pricing , if the db stays below 100MB, it is $ 4.99 per month instead of the original $ 9.99 base cost. It depreciates daily, so even if you have temporary spikes and go into the 1 + GB range, you still have a completely accessible cache repository.



Another possible solution would be to use Sticky Sessions like this example:



All Articles