2011-11-04 1 views
3

컨트롤러 동작이 RedirectResult 결과를 반환 할 때 outputcache 필터가 적용되지 않습니다. 의 Web.config에서OutputCache가 RedirectResult를 캐시하지 않습니다.

: HomeController.cs에서

<system.web> 
<caching> 
<outputCache enableOutputCache="true"></outputCache> 
    <outputCacheSettings> 
    <outputCacheProfiles> 
    <add name="ShortTime" enabled="true" duration="300" noStore="false" /> 
    </outputCacheProfiles> 
    </outputCacheSettings> 
    </caching> ... 

:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 

namespace MvcOutputCacheRedir.Controllers 
{ 
    public class HomeController : Controller 
    { 
     [OutputCache(CacheProfile = "ShortTime")] 
     public ActionResult Index() 
     { 
      ViewBag.Message = "Welcome to ASP.NET MVC!"; 
      return View(); 
     } 

     [OutputCache(CacheProfile = "ShortTime")] 
     public ActionResult About() 
     { 

      // Output cache works as expected 
      // return View(); 

      // Output cache has no effect 
      return Redirect("Index"); 
     } 
    } 
} 

내가 여기

은 ASP.Net MVC3 기본 인터넷 웹 응용 프로그램의 문제를 재현하는 방법입니다 어디서나이 동작을 찾을 수 없습니다 ...이게 정상입니까? 그렇다면 해결 방법은 무엇입니까?

답변

4

이것은 절대적으로 의도 된 동작입니다. OutputCacheAttribute는 문자열 생성 ActionResults에만 사용됩니다. 당신이 (반사판은/ILSpy 당신의 친구입니다)로 보일 것이다 경우에 실제로, 당신은 특별히이 볼 것입니다 :

string uniqueId = this.GetChildActionUniqueId(filterContext); 
string text = this.ChildActionCacheInternal.Get(uniqueId, null) as string; 
if (text != null) 
{ 
    filterContext.Result = new ContentResult 
    { 
     Content = text 
    }; 
    return; 
} 

나는 어쩌면 리디렉션의 결과도 "decesion는"시간/자원이 될 수 있습니다, 당신의 이유를 볼 수 있습니다 소비하지만, 이런 종류의 "의사 결정 캐싱"을 직접 구현해야 할 것입니다.

+0

나는 HTTP 내용이 200이나 302 상태 코드 였을 때 더 오래 캐시 될 것으로 기대했다 ... 감사합니다. – 80n