This question:
Is it possible to share HttpRuntime.Cache between multiple web servers?
..Relates to http://msdn.microsoft.com/en-us/library/system.web.caching.aspx
..I think I know the answer, but for everyone's benefit, with the newer:
http://msdn.microsoft.com/en-us/library/system.runtime.caching.aspx
It is realistically possible? Or would one be better off using memcached / AppFabric / redis / xyz.
MemoryCache does not allow you to share memory between processes as the memory used to cache objects is bound to the application pool. That's the nature of any in-memory cache implementation you'll find. The only way to actually use a shared cache is to use a distributed cache.
Runtime caching refers to gradually adding responses to a cache "as you go". While runtime caching doesn't help with the reliability of the current request, it can help make future requests for the same URL more reliable.
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.
"text": "When system stores the data in a RAM, it is called in-memory caching. It is the simplest cache as compared to the other cache forms. It sits between applications and databases to deliver responses at high speeds by storing data from earlier requests or copied directly from databases."
HttpRuntime.Cache runs in-process (i.e., in server memory) and cannot be shared between multiple web servers. You can extend the mentioned System.Runtime.Caching with a custom provider to centralize caching using a platform such as SQL Server or a dedicated server.
Recommended multi-web server caching strategy would definitely depend on the environment.
On the lower end of scale, using SQL Server is a quick option that is probably familiar to a .NET developer. Another option is using a web service (e.g., WCF) to centralize cached data calls.
On the higher end, you have mentioned the leaders in the field: memcached, AppFabric, Redis, etc. If these are already setup in your environment and/or you are familiar with them I could definitely see using them whenever you have multiple web servers (big or small).
I recommend at least checking out Redis. It's the newer category of the group mentioned but it's lightweight, fast and in addition to the key/value store it has other functionality great for distributed systems such as pub/sub.
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