HTML 도우미에서 출력 캐싱을 사용하려고합니다. 그러나 속성 세트가 있어도이 코드 블록은 Helper 메서드가 호출 될 때 항상 입력됩니다. 이 시나리오에서는 outputcache 특성이 작동하지 않으므로 HTML 도우미에서 "비싼"쿼리를 캐싱하는 것이 좋습니다.MVC HTML 도우미에서 '비싼'쿼리를 캐시하는 데 권장되는 방법은 무엇입니까?
[OutputCache(Duration = 60)]
public static MvcHtmlString CountryDropDownListFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, object selectedValue)
{
var doc = new XmlDocument();
doc.Load(HttpContext.Current.Server.MapPath("~/App_Data/countries.xml"));
var items = new Dictionary<string, string>();
foreach (XmlNode node in doc.SelectNodes("//country"))
{
items.Add(node.InnerText, node.InnerText);
}
return html.DropDownListFor(expression, new SelectList(items, "key", "value", selectedValue));
}