Output Caching in ASP.Net MVC
When building GotThatGame.Com I tried to avoid making a quest for something useful into a vendetta for perfection; however, some improvements only take moments in MVC so I took a moment to apply them. Output caching in MVC is a simple performance improvement that keeps the HTML output of an action in memory and serves subsequent requests quickly from memory.
To enable it for an action, simply apply the OutputCache attribute to an action and when it's called. When first implementing, I could think of a few complex scenarios that left me with lingering questions. For instance, child actions seemed to obviously be not subject to independent caching, but what about redirect actions? I put together a demo solution in Visual Studio that is available on GitHub:
It contains demos for actions, actions with children, and action with partials, plus redirecting between actions. Spoiler alert: it only caches if the root action is attributed, and only stores everything; except when it doesn't. It's likely the most thorough introduction to output caching a programmer can find on the internet.