Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to share HttpRuntime.Cache between multiple web servers?

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

We now need to deploy the application across 2 load balanced web servers.

This being the case, each web server will have its own cache, which is not ideal because if a user requests data from webserver1 it will be cached, but there next request might go to webserver2, and the data that their previous request cached won't be available.

Is it possible to use a shared-cache provider to share the HttpRuntime.Cache between the two web servers or to replicate the cache between them, so that the same cache will be available on both web servers? If so, what can I do to solve this problem?

like image 836
DaveDev Avatar asked Nov 10 '10 12:11

DaveDev


People also ask

Where is Httpruntime cache stored?

Cache is stored in web server memory.

What is distributed Caching in asp net?

A distributed cache is a cache shared by multiple app servers, typically maintained as an external service to the app servers that access it. A distributed cache can improve the performance and scalability of an ASP.NET Core app, especially when the app is hosted by a cloud service or a server farm.


3 Answers

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

like image 142
LukeH Avatar answered Nov 03 '22 14:11

LukeH


Nope, it's not possible. You have to use so called ditributed cache like Microsoft AppFabric Caching or very popupar open source product memcached.

like image 30
Sergejus Avatar answered Nov 03 '22 13:11

Sergejus


It sounds from your question that you've got user data it the cache? In that case I'd be with Aliostad and say dont go there!

HttpRuntime cache should be used for static but regularly used items that come from the database, the main purpose should be preventing database hits that would otherwise occur on every request regardless of user... so things like options in a combobox or certian configuration settings

If you do genuinely need caching for user data, then as above Memcached, Appfabric or nvelocity

There are layers of caching suitable for different needs, having only 2 webservers suggests that you dont yet require the Distributed caching frameworks above.

What is the server load, and what is the limiting factor, CPU, RAM, Network Bandwith? On your DB or your webservers? Each of these indicates a different caching strategy.

like image 1
stevenrcfox Avatar answered Nov 03 '22 14:11

stevenrcfox