3

I'm writing an ASP.NET MVC site where I'm running into a dilmena on how to set up proper caching. I'm trying to achieve something similar to how Stack Overflow works with caching, in that all pages are cached while:

  • Showing the username of the current user, as well as badges and reputation
  • Dynamically hiding/showing certain action links (e.g., the "edit" link on a question is only visible to some users)
  • and more

How is this implemented?

I've tried looking through the SEDE code, but haven't found anything related to caching (probably because SEDE runs on Azure, so it's more complicated). One possible strategy that I can think of is donut or substitution caching, but Phil Haack says that it's not recommended for ASP.NET MVC 2.

Thanks!

5
  • Wouldn't that be a fine question for SE if you decouple it from "How does SO do ...?" and make it "How to do caching for [specific situation]?"? Commented Aug 10, 2010 at 21:20
  • @Georg sure - hold on, you mean, "Wouldn't that be a fine question for SO," right? :) Commented Aug 11, 2010 at 1:25
  • Oops, yes - of course i meant SO. Commented Aug 11, 2010 at 1:48
  • @Georg I've asked a question or two on SO about how to accomplish caching while using things like AuthorizeAttribute. Unfortunately, the consensus there has been donut caching, which is strongly discouraged (at least by Phil Haack) for MVC2. That's why I went here, to ask how it works on SO, because the SO experience, in terms of caching, is what I'm looking to accomplish. Commented Aug 11, 2010 at 7:01
  • Downvote w/o explanation = :( Commented Aug 11, 2010 at 19:29

2 Answers 2

9

We basically don't cache at all for logged in users, so that's your pivot point.

And remember, 90%+ of our traffic is from Google and almost all anonymous by definition..

4
  • Thanks for your answer! I didn't think of that. Guess I'm just going to grab the OutputCacheAttribute source and derive from it to check whether the request is authenticated first. Commented Aug 11, 2010 at 1:26
  • How would I go about ignoring outputcache for logged users?
    – Tadeu Maia
    Commented Jun 22, 2011 at 19:04
  • @Jeff your answer needs more elaboration please
    – Korayem
    Commented Jul 29, 2011 at 22:52
  • @Jeff So if I am logged in and visit the FAQ, none of that is being retrieved from a cache of any kind? In my scenario I have some pages that are identical for all users except for the header displaying a user name, similar to SO's FAQ page.
    – AaronLS
    Commented Aug 22, 2012 at 19:28
0

It's possible in ASP.NET MVC 3 by caching Child Actions. This is explained in greater details here:

http://davidhayden.com/blog/dave/archive/2011/01/25/partialpageoutputcachingaspnetmvc3.aspx

Not the answer you're looking for? Browse other questions tagged .