<p>So, I was looking over my standard cache utility when preparing to unit test a controller and thought, hey, is accessing the HttpRuntime.Cache directly considered harmful in MVC?</p>

<p>I wrap the cache in a proxy class that implements a cache-like interface (tho much simpler) so that I can mock it during tests.  But I'm wondering if that's already done for me in the new framework.  I can't find anything, however.</p>

<p>Here's an idea of how I do it:</p>

<pre><code>public ActionResult DoStuffLol(guid id)
{
  var model = CacheUtil.GetOrCreateAndStore(
                  "DoStuffLolModel",
                  () =&gt;
                  {
                    /* construct model here; time consuming stuff */
                    return model;
                  });
  return View("DoStuffLol", model);
}
</code></pre>

<p>So, has the old patterns of accessing the cache changed?  Are there any better patterns for caching action results in MVC?</p>

Add the OutputCache attribute to your controller action in order to tell the framework to cache the output for you.  You can read more about this attribute in
ScottGu's blog post on ASP.NET Preview 4
.
Don't combine this with the Authorize attribute
, however.