I am using ASP.NET MVC 4 with WEB API
I have the following action, in the action shown below, my service method makes a db call to DoMagic() method and
As already mentioned by OakNinja, output caching via [OutputCache] attributes is currently not supported by the ASP.NET Web API.
However, there are a few open source implementations filling the gap:
A small library bringing caching options, similar to MVC's "OutputCacheAttribute", to Web API actions.
Github: https://github.com/filipw/Strathweb.CacheOutput
License: Apache v2
An implementation of HTTP Caching in ASP.NET Web API for both client-side and server-side.
Github: https://github.com/aliostad/CacheCow
License: MIT
Note: According to the projects README, the library does not support attribute routing:
Currently CacheCow's attribute setting does not work with Attribute Routing. And I personally think you should not use Attribute Routing... (Source: https://github.com/aliostad/CacheCow/blob/master/README.md)
There is a nice blog post by Scott Hanselmann covering both feature sets.