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

Order of route values shouldn't impact key built #65

Open jonathanjto opened 6 years ago

jonathanjto commented 6 years ago

Hi,

When manipulating items using the methods of the OutputCacheManager, RemoveItem for example.

The order of the "RouteValues" should not be important.

Just add "OrderBy" key to this code in the KeyBuilder class for the method public string BuildKey(string controllerName, string actionName, RouteValueDictionary routeValues)


            if (routeValues != null)
            {
                foreach (var routeValue in routeValues.OrderBy(c => c.Key))
                {
                    builder.Append(BuildKeyFragment(routeValue));
                }
            }

Best regards

jonathanjto commented 6 years ago

// Same here, if no value in params - don't use it in the key (area empty or not specified should be the same key fragment)

        public string BuildKeyFragment(KeyValuePair<string, object> routeValue)
        {
            var value = routeValue.Value?.ToString().ToLowerInvariant() ?? "<null>";
            if (!string.IsNullOrWhiteSpace(value))
            {
                return string.Format("{0}={1}#", routeValue.Key.ToLowerInvariant(), value);
            }
            return "";
        }