2011-02-04 53 views
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的方法。

然后我意识到NewsAsyncVaryByParam有关,所以将该属性放在该方法上可能更有意义。

回答

6

OutputCache参数在void NewsAsync方法上,而不是ActionResult NewsCompleted方法。 (由实验确定)