Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MemoryCache object and load balancing

I'm writing a web application using ASP .NET MVC 3. I want to use the MemoryCache object but I'm worried about it causing issues with load balanced web servers. When I google for it looks like that problem is solved on the server ie using AppFabric. If a company has load balanced servers is it on them to make sure they have AppFabric or something similar running? or is there anything I can or should do as a developer for this?

like image 266
Four_0h_Three Avatar asked Jun 05 '12 13:06

Four_0h_Three


1 Answers

First of all, for ASP.NET you should look at the ASP.NET Cache instead of MemoryCache. MemoryCache is a generic caching API that was introduced in .NET 4.0 to provide an equivalent of the ASP.NET Cache in non-web applications.

You're correct to say that AppFabric resolves the issue of multiple servers having their own instances of cached data, in that it provides a single logical cache accessible from all your web servers. Before you leap on it as the solution to your problem, there's a couple of things to consider:

  • It does not ship as part of Windows Server - it is, as you say, on you to install it on your servers if you want to use it. When AppFabric was released, there was a suggestion that it would ship as part of the next release of Windows Server, but I haven't seen anything about Windows Server 2012 that confirms that to be the case.

  • You need extra servers for it, or at least you're advised to have them. Microsoft's recommendation for AppFabric is that you run it on dedicated servers. Which means that whilst AppFabric itself is a free download, you may be incurring additional Windows Server licence costs. Speaking of which...

  • You might need Enterprise Edition licences. If you want to use the High Availability features of AppFabric, you can only do this with servers running Enterprise Edition, which is a more expensive licence than Standard Edition.

  • You might not need it after all. Some of this will depend on your application and why you want to use a shared caching layer. If your concern is that caches on multiple servers could get out of sync with the database (or indeed each other), some judicious use of SqlCacheDependency objects might get you past the issue.

like image 194
PhilPursglove Avatar answered Oct 11 '22 05:10

PhilPursglove