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?
Cache is stored in web server memory.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With