Can I share HttpRuntime.Cache between multiple web servers?

We have a web application that stores all the site data in HttpRuntime.Cache .

Now we need to deploy the application on two load balanced web servers.

In this case, each web server will have its own cache, which is not ideal, because if the user requests data from webserver1, it will be cached, but the next request can go to webserver2 and the data that their previous cache request would not be available.

Can I use a sharing provider to share HttpRuntime.Cache between two web servers or to replicate a cache between them so that the same cache is accessible on both web servers? If so, what can I do to solve this problem?

+7
c # caching webserver
source share
4 answers

No, you cannot use the ASP.NET built-in cache, but you can use something like memcached or AppFabric instead.

+6
source

No, It is Immpossible. You should use a so-called ditributed cache, such as Microsoft AppFabric Caching or the very popular memcached open source product.

+1
source

Do not go there. Usually a cache is a static object; it lives only in AppDomain. In manual updating, this is a world of pain and is strongly advised against.

You can use a number of caching solutions that are located in front of your server for this purpose.

0
source

From your question, does it sound like you have user data in the cache? In this case, I will be with Aliostad and say that it is not there!

The HttpRuntime cache should be used for static but regularly used items that come from the database, the main goal should be to prevent access to databases that would otherwise occur on every request regardless of the user ... so things like options in combobox or certian configuration settings

If you really need to cache user data, then, as described above, Memcached, Appfabric, or nvelocity

There are caching layers suitable for different needs, and only 2 web servers offer you not to use the distributed caching framework above yet.

What is server load, and what is the limiting factor, CPU, RAM, Network Bandwith? On your database or on your web servers? Each of them points to a different caching strategy.

0
source

All Articles