2010-07-12 2 views
0

SSRS 웹 서비스를 호출하여 보고서 목록 및 각 보고서 매개 변수를 검색합니다. SSRS에는 해당 데이터를 가져올 단일 웹 서비스 메서드가 없으므로 두 단계로 수행해야합니다. 1) 보고서 목록을 가져옵니다. 2) 보고서 목록을 반복하고 각각에 대해 매개 변수를 얻기 위해 웹 서비스 메소드를 호출하십시오.C# : System.Web.Caching을 사용하여 메서드 특성 VS를 수동으로 캐싱

매개 변수를 가져 오기 위해 여러 번 호출 할 때 결과를 캐시해야한다고 생각했습니다. 내 질문은 올바른/최선의 실행 방법인가?

컨트롤러 메서드에서 속성을 사용해야합니까? 하지만 캐시 할 특정 데이터뿐만 아니라 컨트롤러의 전체 출력을 캐시합니다. (의사 코드)

[OutputCache(Duration=3600, VaryByParam="none")] 
public ActionResult GetReportList() 
{ 
    var rService = GetReportService(); 
    var reportList = rService.ListChildren(ReportsRoot, true); 

    foreach (var report in reportList) 
    { 
     rService.GetParameters(report.Name); 
    } 

    return Json(result); 
} 

또는 난 단지 내가 System.Web.Caching 클래스/메소드를 사용하여 필요한 것을 수동으로 캐시 할 통해 이동해야합니까?

답변

1

작업에서 직접 캐싱을 수행하지 않고 캐싱을 처리하기 위해 호출 할 수있는 클래스를 만듭니다. 그런 다음 캐시 호출을 수행할지 또는 처리 할 ActionFilter를 작성할지 결정할 수 있습니다.

아래는 ActionFilter에서 캐시를 처리하고 캐시를 필요로하는 동작으로 전달하는 방법입니다.

ActionFilter.cs

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 
    public sealed class PutStuffInCacheAttribute : ActionFilterAttribute 
    { 
      // Fires before the action 
     public override void OnActionExecuting(ActionExecutingContext filterContext) 
     { 
      base.OnActionExecuting(filterContext); 
       var context = filterContext.HttpContext; 
       SomeData result = (SomeData)context.Cache["reports"]; 
       if (result == null) 
       { 
        var reports = new myReportsListClass();   
        var result = reports.GetReportsData(); 
        context.Cache.Add("reports", result); 
       } 

       filterContext.RouteData.Values.Add("reports", result); 
      } 

      //Fires after the action but before view is complete. 
     public override void OnActionExecuted(ActionExecutedContext filterContext) 
     { 
      base.OnActionExecuted(filterContext); 
     }  
     } 

Controller.cs

[PutStuffInCache] 
public ActionResult GetReportList() 
{ 
    var result = (SomeData)this.RouteData.Values["reports"]; 
    return Json(result); 
} 
+0

태드, 응답에 대한 감사합니다. 당신의 대답에 대해 좀 더 자세히 설명해 주시겠습니까? ActionFilter에 대한 의사 코드가있을 수 있습니다. 나는 C#/.NET에 익숙하지 않다. – Jason