Skip to content

Commit cc2fea6

Browse files
committed
Switched to flag like options.
1 parent 28a255d commit cc2fea6

File tree

5 files changed

+36
-38
lines changed

5 files changed

+36
-38
lines changed

DevTrends.MvcDonutCaching/CacheSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ public class CacheSettings
1010
public string VaryByCustom { get; set; }
1111
public OutputCacheLocation Location { get; set; }
1212
public bool NoStore { get; set; }
13-
public bool IgnorePostData { get; set; }
14-
public bool IgnoreQueryStringData { get; set; }
13+
public OutputCacheOptions Options { get; set; }
1514

1615
public bool IsServerCachingEnabled
1716
{
@@ -22,5 +21,6 @@ public bool IsServerCachingEnabled
2221
Location == OutputCacheLocation.ServerAndClient);
2322
}
2423
}
24+
2525
}
2626
}

DevTrends.MvcDonutCaching/DonutOutputCacheAttribute.cs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ public class DonutOutputCacheAttribute : ActionFilterAttribute, IExceptionFilter
1616
private readonly IKeyGenerator _keyGenerator;
1717
private readonly IExtendedOutputCacheManager _outputCacheManager;
1818
private CacheSettings _cacheSettings;
19-
private bool? _ignorePostData;
20-
private bool? _ignoreQueryStringData;
2119
private bool? _noStore;
20+
private OutputCacheOptions? _options;
2221

2322
public DonutOutputCacheAttribute()
2423
{
2524
var keyBuilder = new KeyBuilder();
2625

2726
_keyGenerator = new KeyGenerator(keyBuilder);
28-
_donutHoleFiller = new DonutHoleFiller(new EncryptingActionSettingsSerialiser(new ActionSettingsSerialiser(), new Encryptor()));
2927
_outputCacheManager = new OutputCacheManager(OutputCache.Instance, keyBuilder);
28+
_donutHoleFiller = new DonutHoleFiller(new EncryptingActionSettingsSerialiser(new ActionSettingsSerialiser(), new Encryptor()));
3029
_cacheSettingsManager = new CacheSettingsManager();
3130
_cacheHeadersHelper = new CacheHeadersHelper();
3231

@@ -94,27 +93,15 @@ public bool NoStore
9493
}
9594
}
9695

97-
public bool IgnoreQueryStringData
98-
{
99-
get
100-
{
101-
return _ignoreQueryStringData ?? false;
102-
}
103-
set
104-
{
105-
_ignoreQueryStringData = value;
106-
}
107-
}
108-
109-
public bool IgnorePostData
96+
public OutputCacheOptions Options
11097
{
11198
get
11299
{
113-
return _ignorePostData ?? false;
100+
return _options ?? OutputCacheOptions.None;
114101
}
115102
set
116103
{
117-
_ignorePostData = value;
104+
_options = value;
118105
}
119106
}
120107

@@ -228,14 +215,13 @@ protected CacheSettings BuildCacheSettings()
228215
{
229216
cacheSettings = new CacheSettings
230217
{
231-
IsCachingEnabled = _cacheSettingsManager.IsCachingEnabledGlobally,
232-
Duration = Duration,
233-
VaryByCustom = VaryByCustom,
234-
VaryByParam = VaryByParam,
235-
Location = (int)Location == -1 ? OutputCacheLocation.Server : Location,
236-
NoStore = NoStore,
237-
IgnorePostData = IgnorePostData,
238-
IgnoreQueryStringData = IgnoreQueryStringData,
218+
IsCachingEnabled = _cacheSettingsManager.IsCachingEnabledGlobally,
219+
Duration = Duration,
220+
VaryByCustom = VaryByCustom,
221+
VaryByParam = VaryByParam,
222+
Location = (int)Location == -1 ? OutputCacheLocation.Server : Location,
223+
NoStore = NoStore,
224+
Options = Options,
239225
};
240226
}
241227
else
@@ -244,14 +230,13 @@ protected CacheSettings BuildCacheSettings()
244230

245231
cacheSettings = new CacheSettings
246232
{
247-
IsCachingEnabled = _cacheSettingsManager.IsCachingEnabledGlobally && cacheProfile.Enabled,
248-
Duration = Duration == -1 ? cacheProfile.Duration : Duration,
249-
VaryByCustom = VaryByCustom ?? cacheProfile.VaryByCustom,
250-
VaryByParam = VaryByParam ?? cacheProfile.VaryByParam,
251-
Location = (int)Location == -1 ? ((int)cacheProfile.Location == -1 ? OutputCacheLocation.Server : cacheProfile.Location) : Location,
252-
NoStore = _noStore.HasValue ? _noStore.Value : cacheProfile.NoStore,
253-
IgnorePostData = IgnorePostData,
254-
IgnoreQueryStringData = IgnoreQueryStringData,
233+
IsCachingEnabled = _cacheSettingsManager.IsCachingEnabledGlobally && cacheProfile.Enabled,
234+
Duration = Duration == -1 ? cacheProfile.Duration : Duration,
235+
VaryByCustom = VaryByCustom ?? cacheProfile.VaryByCustom,
236+
VaryByParam = VaryByParam ?? cacheProfile.VaryByParam,
237+
Location = (int)Location == -1 ? ((int)cacheProfile.Location == -1 ? OutputCacheLocation.Server : cacheProfile.Location) : Location,
238+
NoStore = _noStore.HasValue ? _noStore.Value : cacheProfile.NoStore,
239+
Options = Options,
255240
};
256241
}
257242

DevTrends.MvcDonutCaching/KeyGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public string GenerateKey(ControllerContext context, CacheSettings cacheSettings
3838
{
3939
// note that route values take priority over form values and form values take priority over query string values
4040

41-
if (!cacheSettings.IgnorePostData)
41+
if ((cacheSettings.Options & OutputCacheOptions.IgnoreFormData) != OutputCacheOptions.IgnoreFormData)
4242
{
4343
foreach (var formKey in context.HttpContext.Request.Form.AllKeys)
4444
{
@@ -57,7 +57,7 @@ public string GenerateKey(ControllerContext context, CacheSettings cacheSettings
5757
}
5858
}
5959

60-
if (!cacheSettings.IgnoreQueryStringData)
60+
if ((cacheSettings.Options & OutputCacheOptions.IgnoreQueryString) != OutputCacheOptions.IgnoreQueryString)
6161
{
6262
foreach (var queryStringKey in context.HttpContext.Request.QueryString.AllKeys)
6363
{

DevTrends.MvcDonutCaching/MvcDonutCaching.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<Compile Include="MemoryCacheProvider.cs" />
8888
<Compile Include="OutputCache.cs" />
8989
<Compile Include="OutputCacheManager.cs" />
90+
<Compile Include="OutputCacheOptions.cs" />
9091
<Compile Include="Properties\Annotations.cs" />
9192
<Compile Include="Properties\AssemblyInfo.cs" />
9293
</ItemGroup>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace DevTrends.MvcDonutCaching
4+
{
5+
[Flags]
6+
public enum OutputCacheOptions
7+
{
8+
None = 0x0,
9+
IgnoreQueryString = 0x1,
10+
IgnoreFormData = 0x2,
11+
}
12+
}

0 commit comments

Comments
 (0)