Skip to content

Commit fa36f34

Browse files
committed
Merge remote-tracking branch 'origin/dev' into dev
2 parents cb7eea6 + a07e426 commit fa36f34

File tree

8 files changed

+99
-61
lines changed

8 files changed

+99
-61
lines changed

CONTRIBUTORS.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Paweł Olesiejuk <pawel.olesiejuk@gmail.com> : Fixed codeplex issue #2533
88
Ramgopal <itsramgopal@gmail.com> : Fixed codeplex issue issue #2578
99
Gábor Plesz <gplesz@smarterdb.com> : Work on the demo project.
1010
Luc-Edmond Gaspard <gaspard.le@gmail.com> : Reported and fixed Github issue #5.
11-
11+
anorborg <norborg@gmail.com> : Fixed duplicate key exception PR #27
12+
pstarkov <pstarkov@knoema.com> : Implemented VaryByHeader support #6

DevTrends.MvcDonutCaching/CacheSettings.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public class CacheSettings
2828
/// </value>
2929
public string VaryByParam { get; set; }
3030

31+
/// <summary>
32+
/// Gets or sets the VaryByHeader cache parameter.
33+
/// </summary>
34+
/// <value>
35+
/// The VaryByHeader cache parameter.
36+
/// </value>
37+
public string VaryByHeader { get; set; }
38+
3139
/// <summary>
3240
/// Gets or sets the VaryByCustom cache parameter.
3341
/// </summary>

DevTrends.MvcDonutCaching/DonutOutputCacheAttribute.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ public string VaryByParam
6868
set;
6969
}
7070

71+
/// <summary>
72+
/// Gets or sets the vary-by-header value.
73+
/// </summary>
74+
public string VaryByHeader
75+
{
76+
get;
77+
set;
78+
}
79+
7180
/// <summary>
7281
/// Gets or sets the vary-by-custom value.
7382
/// </summary>
@@ -262,12 +271,13 @@ protected CacheSettings BuildCacheSettings()
262271
cacheSettings = new CacheSettings
263272
{
264273
IsCachingEnabled = CacheSettingsManager.IsCachingEnabledGlobally,
265-
Duration = Duration,
266-
VaryByCustom = VaryByCustom,
267-
VaryByParam = VaryByParam,
268-
Location = (int)Location == -1 ? OutputCacheLocation.Server : Location,
269-
NoStore = NoStore,
270-
Options = Options,
274+
Duration = Duration,
275+
VaryByCustom = VaryByCustom,
276+
VaryByParam = VaryByParam,
277+
VaryByHeader = VaryByHeader,
278+
Location = (int)Location == -1 ? OutputCacheLocation.Server : Location,
279+
NoStore = NoStore,
280+
Options = Options,
271281
};
272282
}
273283
else
@@ -277,12 +287,13 @@ protected CacheSettings BuildCacheSettings()
277287
cacheSettings = new CacheSettings
278288
{
279289
IsCachingEnabled = CacheSettingsManager.IsCachingEnabledGlobally && cacheProfile.Enabled,
280-
Duration = Duration == -1 ? cacheProfile.Duration : Duration,
281-
VaryByCustom = VaryByCustom ?? cacheProfile.VaryByCustom,
282-
VaryByParam = VaryByParam ?? cacheProfile.VaryByParam,
283-
Location = (int)Location == -1 ? ((int)cacheProfile.Location == -1 ? OutputCacheLocation.Server : cacheProfile.Location) : Location,
284-
NoStore = _noStore.HasValue ? _noStore.Value : cacheProfile.NoStore,
285-
Options = Options,
290+
Duration = Duration == -1 ? cacheProfile.Duration : Duration,
291+
VaryByCustom = VaryByCustom ?? cacheProfile.VaryByCustom,
292+
VaryByParam = VaryByParam ?? cacheProfile.VaryByParam,
293+
VaryByHeader = VaryByHeader ?? cacheProfile.VaryByHeader,
294+
Location = (int)Location == -1 ? ((int)cacheProfile.Location == -1 ? OutputCacheLocation.Server : cacheProfile.Location) : Location,
295+
NoStore = _noStore.HasValue ? _noStore.Value : cacheProfile.NoStore,
296+
Options = Options,
286297
};
287298
}
288299

DevTrends.MvcDonutCaching/HtmlHelperExtensions.cs

Lines changed: 41 additions & 41 deletions
Large diffs are not rendered by default.

DevTrends.MvcDonutCaching/KeyGenerator.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ public string GenerateKey(ControllerContext context, CacheSettings cacheSettings
6060

6161
string areaName = null;
6262

63-
if (routeData.DataTokens.ContainsKey(DataTokensKeyArea))
63+
if (
64+
routeData.DataTokens.ContainsKey(DataTokensKeyArea) &&
65+
routeData.DataTokens[DataTokensKeyArea] != null
66+
)
6467
{
6568
areaName = routeData.DataTokens[DataTokensKeyArea].ToString();
6669
}
@@ -83,7 +86,6 @@ public string GenerateKey(ControllerContext context, CacheSettings cacheSettings
8386
if (!context.IsChildAction)
8487
{
8588
// note that route values take priority over form values and form values take priority over query string values
86-
8789
if ((cacheSettings.Options & OutputCacheOptions.IgnoreFormData) != OutputCacheOptions.IgnoreFormData)
8890
{
8991
foreach (var formKey in context.HttpContext.Request.Form.AllKeys)
@@ -107,7 +109,7 @@ public string GenerateKey(ControllerContext context, CacheSettings cacheSettings
107109
{
108110
foreach (var queryStringKey in context.HttpContext.Request.QueryString.AllKeys)
109111
{
110-
// queryStringKey is null if url has qs name without value. e.g. test.com?q
112+
// queryStringKey is null if url has as name without value. e.g. test.com?q
111113
if (queryStringKey == null || routeValues.ContainsKey(queryStringKey.ToLowerInvariant()))
112114
{
113115
continue;
@@ -133,7 +135,8 @@ public string GenerateKey(ControllerContext context, CacheSettings cacheSettings
133135
else if (cacheSettings.VaryByParam != "*")
134136
{
135137
var parameters = cacheSettings.VaryByParam.ToLowerInvariant().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
136-
routeValues = new RouteValueDictionary(routeValues.Where(x => parameters.Contains(x.Key)).ToDictionary(x => x.Key, x => x.Value));
138+
routeValues = new RouteValueDictionary(routeValues.Where(x => parameters.Contains(x.Key))
139+
.ToDictionary(x => x.Key, x => x.Value));
137140
}
138141
}
139142

@@ -144,6 +147,16 @@ public string GenerateKey(ControllerContext context, CacheSettings cacheSettings
144147
context.HttpContext.ApplicationInstance.GetVaryByCustomString(HttpContext.Current, cacheSettings.VaryByCustom);
145148
}
146149

150+
if (!string.IsNullOrEmpty(cacheSettings.VaryByHeader))
151+
{
152+
var headers = cacheSettings.VaryByHeader.ToLowerInvariant().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
153+
var existingHeaders = context.HttpContext.Request.Headers.AllKeys.Where(x => headers.Contains(x.ToLowerInvariant()));
154+
foreach (var header in existingHeaders)
155+
{
156+
routeValues[header] = context.HttpContext.Request.Headers[header];
157+
}
158+
}
159+
147160
var key = _keyBuilder.BuildKey(controllerName, actionName, routeValues);
148161

149162
return key;

DevTrends.MvcDonutCaching/OutputCacheManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public OutputCacheManager(OutputCacheProvider outputCacheProvider, IKeyBuilder k
2323
_keyBuilder = keyBuilder;
2424
}
2525

26+
public IKeyBuilder KeyBuilder
27+
{
28+
get { return _keyBuilder; }
29+
}
30+
2631
public void AddItem(string key, CacheItem cacheItem, DateTime utcExpiry)
2732
{
2833
_outputCacheProvider.Add(key, cacheItem, utcExpiry);
@@ -114,7 +119,7 @@ public void RemoveItems([AspMvcController] string controllerName, [AspMvcAction]
114119
public void RemoveItems([AspMvcController] string controllerName, [AspMvcAction] string actionName, RouteValueDictionary routeValues)
115120
{
116121
var enumerableCache = _outputCacheProvider as IEnumerable<KeyValuePair<string, object>>;
117-
122+
118123
if (enumerableCache == null)
119124
{
120125
throw new NotSupportedException("Ensure that your custom OutputCacheProvider implements IEnumerable<KeyValuePair<string, object>>.");

DevTrends.MvcDonutCaching/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// [assembly: AssemblyConfiguration("")]
77
[assembly: AssemblyCompany("DevTrends")]
88
[assembly: AssemblyProduct("DevTrends.MvcDonutCaching")]
9-
[assembly: AssemblyCopyright("Copyright 2013 © MvcDonutCaching contributors")]
9+
[assembly: AssemblyCopyright("Copyright 2014 © MvcDonutCaching contributors")]
1010
// [assembly: AssemblyTrademark("")]
1111
// [assembly: AssemblyCulture("")]
1212
[assembly: ComVisible(false)]

nuget/MvcDonutCaching.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>MvcDonutCaching</id>
5-
<version>1.3.0-rc1</version>
5+
<version>1.3.0</version>
66
<authors>MvcDonutCaching contributors</authors>
77
<owners>Clément Bourgeois</owners>
88
<licenseUrl>https://raw.github.com/moonpyk/mvcdonutcaching/master/LICENSE.txt</licenseUrl>

0 commit comments

Comments
 (0)