5
votes

I'm looking into caching with ASP.NET MVC and I am also in middle of finalizing web-host. I've two questions...

1) Does caching pose issue when done on shared hosting environment since resources are shared and all? This question may sound silly, but I just do not know how caching works behind the scene.

2) Before I implement caching, I want to ask if this approach makes sense. I will cache as much as possible, and invalidate it when needed. However, how does caching work for a list of item that gets updated very frequently, say in a minute or something. For example, the front page of StackOverflow, with so many questions being added every minute, can the front page actually be cached?

EDIT: 3) I would also like to discuss how caching works with paging and all.

1
you have to categorize the items which you want to cache. the things which update frequently is not a good thing to be cached. In the scenario of stackoverflow I will not make it cache-able. Things like site wide setting user account info when he logins, etc. these things can be cached. Also, if you can use any third party cache software it will be best like memcached.Shakeeb Ahmed
so you are implying memcached is better than ASP.NET caching?TPR
its not as simple as better or worse. If the built in caching does what you need then you ain't going to do better... what you should do, however, is put your own wrapper (as an interface) around the cache - that way it will be simple to change the underlying implementation should you need to.Murph

1 Answers

1
votes

I think a minute is a long time if you are servicing 200 requests a second and I would have thought that SO uses asp.net output caching for the front page. They will also most likely use some sort of donut caching aswell to cache the non-user specific portions.

Asp.net MVC uses the standard ASP.NET caching provider unchanged. On a shared host Caching should work correctly however be aware that the host can lock down cache settings if they choose to on a machine level. The Cache provider deals with memory management and will remove items from the cache if memory usage gets too high. I suggest you read the MSDN pages on caching here.

The complication comes from a clustered environment not so much a shared host. On a clustered environment the cache is not distributed to all machines, so each machine has a separate copy of the cache. If this poses a problem then you will need to investigate a distributed caching solution, but in most simple cases this is fine.

With regard to paging, the output caching feature of asp.net allows you to vary-by query string so if you have www.url.com?page=1 this will be stored separately in the cache from www.url.com?page=2.