What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

This question already has an answer here:

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!

share|improve this question

marked as duplicate by animuson Jul 25 at 19:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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]?"? –  Georg Fritzsche Aug 10 '10 at 21:20
    
@Georg sure - hold on, you mean, "Wouldn't that be a fine question for SO," right? :) –  Maxim Zaslavsky Aug 11 '10 at 1:25
    
Oops, yes - of course i meant SO. –  Georg Fritzsche Aug 11 '10 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. –  Maxim Zaslavsky Aug 11 '10 at 7:01
    
Downvote w/o explanation = :( –  Maxim Zaslavsky Aug 11 '10 at 19:29

2 Answers 2

up vote 8 down vote accepted

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..

share|improve this answer
    
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. –  Maxim Zaslavsky Aug 11 '10 at 1:26
    
How would I go about ignoring outputcache for logged users? –  Tadeu Maia Jun 22 '11 at 19:04
    
@Jeff your answer needs more elaboration please –  Korayem Jul 29 '11 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 Aug 22 '12 at 19:28

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

share|improve this answer

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