Skip to content

Commit c0e4ec6

Browse files
committed
fixed duplicate key exception
If the value of VaryByCustom is equal to a key that has already been added to the route values, there will be a conflict. Instead of add, it now adds or replaces the given key.
1 parent 39dc100 commit c0e4ec6

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

DevTrends.MvcDonutCaching/KeyGenerator.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ public string GenerateKey(ControllerContext context, CacheSettings cacheSettings
106106

107107
if (!string.IsNullOrEmpty(cacheSettings.VaryByCustom))
108108
{
109-
routeValues.Add(
110-
cacheSettings.VaryByCustom.ToLowerInvariant(),
111-
context.HttpContext.ApplicationInstance.GetVaryByCustomString(HttpContext.Current, cacheSettings.VaryByCustom)
112-
);
109+
// if there is an existing route value with the same key as varybycustom, we should overwrite it
110+
routeValues[cacheSettings.VaryByCustom.ToLowerInvariant()] =
111+
context.HttpContext.ApplicationInstance.GetVaryByCustomString(HttpContext.Current, cacheSettings.VaryByCustom);
113112
}
114113

115114
var key = _keyBuilder.BuildKey(controllerName, actionName, routeValues);

0 commit comments

Comments
 (0)