使用提琴手来看看HTTP响应 - 可能是响应头有:缓存控制:没有缓存。
它`可能是一个好主意,用Strathweb.CacheOutput.WebApi2代替:如果您在使用则Web API 2
。然后,你的代码是:
public class ValuesController : ApiController
{
[CacheOutput(ClientTimeSpan = 3600, ServerTimeSpan = 3600)]
public int Get(int id)
{
return new Random().Next();
}
}
其他你可以尝试使用自定义属性
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();
}
}
https://codewala.net/2015/05/25/outputcache-doesnt-work-with-web-api-why-a-solution/ –