When attempting to set a different OutputCache property on a partial view I find that the PartialView cache is using the parents output cache duration. With the following code I would hope that the RenderPartial would result in a shorter OutputCache duration but I find that it is the same as the parent view (10 seconds)
public class HomeController : Controller
{
[OutputCache(Duration=10, VaryByParam="none")]
public ActionResult Index()
{
ViewBag.Message = "Time now: "+ DateTime.Now.ToString();
return View();
}
[ChildActionOnly]
[OutputCache(Duration=5, VaryByParam="none")]
public PartialViewResult LogonPartial()
{
return PartialView("_LogOnPartial");
}
}
With this simple example showing the DateTime.Now in the partial view I find that the PartialView does not clear it's cache until the parent view flushes his where I would hope that the Partial view clear's cache every 5 seconds (not every 10 as the parent view does). With the examples that I have seen using OutputCache on a PartialView the cache is implemented on the PartialView not the containing view. Does anyone know if this is a limitation of caching in MVC3 or if there is another way to handle different caching mechanisms on the same page? Thanks in advance!