gpt4 book ai didi

asp.net-mvc-3 - 异步 Controller 输出缓存

转载 作者:行者123 更新时间:2023-12-01 12:59:18 26 4
gpt4 key购买 nike

实现 asynchronous controller 时ASP.NET MVC 中的 action,如果我想输出缓存 ActionResult,我应该把 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 关联,因此将属性放在该方法上可能更有意义。

最佳答案

OutputCache 参数用于 void NewsAsync 方法,而不是 ActionResult NewsCompleted 方法。 (通过实验确定)

关于asp.net-mvc-3 - 异步 Controller 输出缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4893964/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com