2015-05-07 26 views
0

我正確的說,在ASP.NET 5中ResponseCacheAttribute已經替換了以前的ASP.NET MVC版本中使用的OutputCacheAttribute?它可以用來緩存API控制器的響應嗎?如果沒有,微軟會提供什麼呢?我嘗試了兩種免費的WebAPI2解決方案,但沒有留下深刻的印象。在ASP.NET 5中輸出緩存API控制器

+0

如果您使用ASP.NET 5,則不應再有任何'ApiController'類型。你應該只有'Controller'類型。 'ResponseCacheAttribute'在'Controller'操作方法上工作。 ASP.NET 5的目標之一是統一MVC的Controller和WebAPI的ApiController。 –

+1

那太棒了!但是爲什麼位於'Microsoft.AspNet.Mvc'命名空間的'ResponseCacheAttribute'然後(我在看github)呢? – UserControl

+2

ResponseCache不是OutputCache的替代品。 ResponseCache不會在內存中緩存輸出。 –

回答

2

是的,您將可以使用ResponseCacheAttribute

因爲Web Api Controller和MVC Controller之間沒有區別,所以您可以對兩者使用相同的屬性。無論是ResponseCacheAttribute,AuthorizeAttribute,RouteAttribute還是任何其他,這都適用。