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开发者_如何学C will be available on both web servers? If so, what can I do to solve this problem?
No, you can't share the built-in ASP.NET cache, but you could use something like memcached or AppFabric instead.
Nope, it's not possible. You have to use so called ditributed cache like Microsoft AppFabric Caching or very popupar open source product memcached.
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.
Don't go there. Normally, cache being a static object, only lives in the AppDomain. Manually updating these is a world of pain and strongly advise against.
You can use a number of caching solutions that sit in front of your server for that kind of purpose.
精彩评论