moonpyk / mvcdonutcaching

ASP.NET MVC Extensible Donut Caching brings donut caching to ASP.NET MVC 3 and later. The code allows you to cache all of your page apart from one or more Html.Actions which can be executed every request. Perfect for user specific content.
https://github.com/moonpyk/mvcdonutcaching
MIT License
142 stars 49 forks source link

Action Key Generation Area/Action Confusion #14

Closed ghstahl closed 10 years ago

ghstahl commented 10 years ago

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);
        }
    }
} 

Added the following;

controllerName = context.Controller.ToString();

You are building a key simply 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;
         }
    }
}
moonpyk commented 10 years ago

Bitch issue title award 2013 :+1:

Will get fixed though, thanks for reporting.