With the help of a violinist, take a look at the HTTP response - perhaps the response header contains: Cache-Control: no cache.
If you are using Web API 2, then:
It is probably best to use Strathweb.CacheOutput.WebApi2. Then you will get the code:
public class ValuesController : ApiController
{
[CacheOutput(ClientTimeSpan = 3600, ServerTimeSpan = 3600)]
public int Get(int id)
{
return new Random().Next();
}
}
else
public class CacheWebApiAttribute : ActionFilterAttribute
{
public int Duration { get; set; }
public override void OnActionExecuted(HttpActionExecutedContext filterContext)
{
filterContext.Response.Headers.CacheControl = new CacheControlHeaderValue()
{
MaxAge = TimeSpan.FromMinutes(Duration),
MustRevalidate = true,
Private = true
};
}
}
public class ValuesController : ApiController
{
[CacheWebApi(Duration = 3600)]
public int Get(int id)
{
return new Random().Next();
}
}