1

Closed

Area/Action Confused?

description

I have 2 HomeController(s) based upon your demo.
The only difference is that they are in different areas

Both Index() actions get called correctly.
/Sports and /Free get routed correctly

Both Index() actions redirect to Simple()
Once the first Simple() action is called that is the one that is cached for everyone. No Simple() action in either of these controllers is ever called again for the duration of the cache.

It appears that there is an issue with cache key confusion here. Could be related to someone asking for area support. Anyway, showstopper for me..


namespace Pingo.Demo.Area.Areas.Sports.Controllers
{
public class HomeController : Controller
{
    //
    // GET: /Sports/Home/

    public ActionResult Index()
    {
        return RedirectToAction("Simple");

    }

    [DonutOutputCache(Duration = 24 * 3600)]
    public ActionResult Simple()
    {
        return View(DateTime.Now);
    }
}
}

namespace Pingo.Demo.Area.Areas.Free.Controllers
{
public class HomeController : Controller
{
    //
    // GET: /Free/Home/

    public ActionResult Index()
    {
        return RedirectToAction("Simple");

    }

    [DonutOutputCache(Duration = 24 * 3600)]
    public ActionResult Simple()
    {
        return View(DateTime.Now);
    }
}
}

This is based upon
Closed Dec 12, 2013 at 3:34 PM by moonpyk
Issue reported on github

comments

ghstahl wrote Dec 11, 2013 at 3:03 PM

Added the following;
controllerName = context.Controller.ToString();

You are building a key simple based upon the controller name, i.e. Home.
You should be building it using the full controller name, i.e. {namespace}.{class}

Fixed my problem, but I don't want maintain my own branch :(
namespace DevTrends.MvcDonutCaching
{
    public class KeyGenerator : IKeyGenerator
    {
         public string GenerateKey(ControllerContext context, CacheSettings cacheSettings)
         {
              ....
              controllerName = context.Controller.ToString();
              var key = _keyBuilder.BuildKey(controllerName, actionName, routeValues);

              return key;

         }
    }
}