Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc - caching

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.

like image 951
TPR Avatar asked Nov 15 '22 12:11

TPR


1 Answers

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.

like image 165
madcapnmckay Avatar answered Dec 09 '22 18:12

madcapnmckay