It seems outputcache filter does not apply when a controller action returns a RedirectResult result.
Here is how to reproduce the problem with ASP.Net MVC3 default Internet Web Application :
In Web.config :
<system.web>
<caching>
<outputCache enableOutputCache="true"></outputCache>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ShortTime" enabled="true" duration="300" noStore="false" />
</outputCacheProfiles>
</outputCacheSettings>
</caching> ...
In HomeController.cs :
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");
}
}
}
I cannot find this behavior specified anywhere ... is this normal? If so, any workaround ?