3
나는 다음과 같은 조치가 :ASP.NET MVC OutputCacheAttribute : 매개 변수가 설정된 경우 캐시하지 않습니까?
public class HomeController : Controller
{
public ActionResult Index(int? id) { /* ... */ }
}
내가 해당 작업을 [OutputCache]
하고 싶습니다,하지만 난 그 싶습니다을 중 하나는 캐시를 사용하지 않는
id == null
경우; 또는- 캐시가 다른 경우에는
id == null
인 경우 캐시를 사용합니다.
나는 내가 이것을 달성 할 수 있다고 생각 :
public class HomeController : Controller
{
[OutputCache(VaryByParam = "none", Duration = 3600)]
public ActionResult Index() { /* ... */ }
[OutputCache(VaryByParam = "id", Duration = 60)]
public ActionResult Index(int id) { /* ... */ }
}
그러나이 솔루션은
id
실제로 선택 사항이 작업을 의미한다, 그래서 이것은 몇 가지 코드의 반복을 만들 수 있습니다. 물론 나는 비슷한 것을 할 수있다.
public class HomeController : Controller
{
[OutputCache(VaryByParam = "none", Duration = 3600)]
public ActionResult Index() { return IndexHelper(null); }
[OutputCache(VaryByParam = "id", Duration = 60)]
public ActionResult Index(int id) { return IndexHelper(id); }
private ActionResult IndexHelper(int? id) { /* ... */ }
}
그러나 이것은 추한 것처럼 보인다.
어떻게 구현하나요?
확실하지, 그래서 하나. – Gregory