3
在ASP.NET MVC中实现asynchronous controller操作时,如果要输出缓存ActionResult
,我应该使用哪种方法将OutputCache
属性置于?AsyncController OutputCache
public class PortalController : AsyncController {
/// HERE...?
[OutputCache(Duration = 60 * 30 /* 30min */, VaryByParam = "city")]
public void NewsAsync(string city) {
AsyncManager.OutstandingOperations.Increment();
NewsService newsService = new NewsService();
newsService.GetHeadlinesCompleted += (sender, e) =>
{
AsyncManager.Parameters["headlines"] = e.Value;
AsyncManager.OutstandingOperations.Decrement();
};
newsService.GetHeadlinesAsync(city);
}
/// ...OR HERE?
[OutputCache(Duration = 60 * 30 /* 30min */, VaryByParam = "city")]
public ActionResult NewsCompleted(string[] headlines) {
return View("News", new ViewStringModel
{
NewsHeadlines = headlines
});
}
}
起初,我以为,它会去上NewsCompleted
,因为那是它返回一个ActionResult
的方法。
然后我意识到NewsAsync
与VaryByParam
有关,所以将该属性放在该方法上可能更有意义。