I am looking for an efficient cache strategy for C#. I am constructing an MVC application however one of my queries targets a historical table with states, etc. Needless to say, the query is highly nested and complex, and I do not want to run it every time a person hits the site, so I decided to cache the data (either the results or the tables themselves). I dont want to store my cache in the Managed heap due to the stop-the-world garbage collection problem which is common with generational GC's and Caches. I was wondering, does the Cache Application Block (http://msdn.microsoft.com/en-us/library/ff650180.aspx) use Unmanaged memory (off the managed heap?). Is there a way to access memory directly via native IO? Any other cache tools worth looking into?
3 Answers
I highly suggest you look at AppFabric Caching. I just implemented for my MVC app and it worked great.
I used this blog to get started:
Let me know if you need some code samples.
Comments
.Net caching frameworks that I am aware of:
- The built in ASP.Net System.Web.Caching (which can be used in non-web applications as long as you don't mind referencing System.Web)
- NCache
- The Microsoft Caching Application Block
- Built in Systen.Runtime.Caching (.Net 4.0 only)
- Windows Azure AppFabric Caching (How to: Configure ASP.NET to use Windows Azure AppFabric Caching)
Although I've looked into various caching frameworks I'm afraid I don't have very much experience with any of them except for System.Web.Caching - this works fine for our purposes.
Comments
You can as well explore the distributed caching options like Memcached or SharedCache. We had used SharedCache for one of our project and it worked well. As suggested in one of the answers you could also try AppFabric. If you are looking at Microsoft based solution then there is a distributed caching famework by Microsoft called Velocity.
Hope this helps.