title: Output caching for an ApiController (MVC4 Web API)
body: <p>I'm trying to cache the output of an <a href="http://msdn.microsoft.com/en-us/library/system.web.http.apicontroller.aspx" rel="noreferrer">ApiController</a> method in Web API.</p>
  
  <p>Here's the controller code:</p>
  
  <pre><code>public class TestController : ApiController
  {
      [OutputCache(Duration = 10, VaryByParam = "none", Location = OutputCacheLocation.Any)]
      public string Get()
      {
          return System.DateTime.Now.ToString();
      }
  }
  </code></pre>
  
  <p>N.B. I'd also tried the OutputCache attribute on the controller itself, as well as several combinations of its parameters.</p>
  
  <p>The route is registered in Global.asax:</p>
  
  <pre><code>namespace WebApiTest
  {
      public class Global : HttpApplication
      {
          protected void Application_Start(object sender, EventArgs e)
          {
              RouteTable.Routes.MapHttpRoute("default", routeTemplate: "{controller}");
          }
      }
  }
  </code></pre>
  
  <p>I get a successful response, but it's not cached anywhere:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Cache-Control: no-cache
  Pragma: no-cache
  Content-Type: application/xml; charset=utf-8
  Expires: -1
  Server: Microsoft-IIS/7.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Date: Wed, 18 Jul 2012 17:56:17 GMT
  Content-Length: 96
  
  &lt;string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;18/07/2012 18:56:17&lt;/string&gt;
  </code></pre>
  
  <p>I was not able to find documentation for output caching in Web API.</p>
  
  <p>Is this a limitation of the Web API in MVC4 or am I doing something wrong?</p>