Skip to content

Commit 2530783

Browse files
author
DevTrends
committed
Fixed KeyBuilder stem issue
Split IOutputCacheManager interface
1 parent a295b97 commit 2530783

File tree

8 files changed

+38
-30
lines changed

8 files changed

+38
-30
lines changed

DevTrends.MvcDonutCaching/CacheSettingsManager.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ public string RetrieveOutputCacheProviderType()
2020
{
2121
return null;
2222
}
23-
else
24-
{
25-
return _outputCacheSection.Providers[_outputCacheSection.DefaultProviderName].Type;
26-
}
23+
24+
return _outputCacheSection.Providers[_outputCacheSection.DefaultProviderName].Type;
2725
}
2826

2927
public OutputCacheProfile RetrieveOutputCacheProfile(string cacheProfileName)

DevTrends.MvcDonutCaching/DevTrends.MvcDonutCaching.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<Compile Include="ActionSettingsSerialiser.cs" />
5353
<Compile Include="CacheSettings.cs" />
5454
<Compile Include="CacheSettingsManager.cs" />
55+
<Compile Include="IExtendedOutputCacheManager.cs" />
5556
<Compile Include="DonutHoleFiller.cs" />
5657
<Compile Include="IActionOutputBuilder.cs" />
5758
<Compile Include="IActionSettingsSerialiser.cs" />

DevTrends.MvcDonutCaching/DonutOutputCacheAttribute.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class DonutOutputCacheAttribute : ActionFilterAttribute
99
private readonly IKeyGenerator _keyGenerator;
1010
private readonly IDonutHoleFiller _donutHoleFiller;
1111
private readonly IActionOutputBuilder _actionOutputBuilder;
12-
private readonly IOutputCacheManager _outputCacheManager;
12+
private readonly IExtendedOutputCacheManager _outputCacheManager;
1313
private readonly ICacheSettingsManager _cacheSettingsManager;
1414

1515
private CacheSettings _cacheSettings;
@@ -23,15 +23,15 @@ public class DonutOutputCacheAttribute : ActionFilterAttribute
2323
public DonutOutputCacheAttribute()
2424
{
2525
var keyBuilder = new KeyBuilder();
26-
_keyGenerator = new KeyGenerator(keyBuilder); ;
26+
_keyGenerator = new KeyGenerator(keyBuilder);
2727
_donutHoleFiller = new DonutHoleFiller(new ActionSettingsSerialiser());
2828
_actionOutputBuilder = new ActionOutputBuilder();
2929
_outputCacheManager = new OutputCacheManager(OutputCache.Instance, keyBuilder);
3030
_cacheSettingsManager = new CacheSettingsManager();
3131
}
3232

3333
internal DonutOutputCacheAttribute(IKeyGenerator keyGenerator, IDonutHoleFiller donutHoleFiller, IActionOutputBuilder actionOutputBuilder,
34-
IOutputCacheManager outputCacheManager, ICacheSettingsManager cacheSettingsManager)
34+
IExtendedOutputCacheManager outputCacheManager, ICacheSettingsManager cacheSettingsManager)
3535
{
3636
_keyGenerator = keyGenerator;
3737
_donutHoleFiller = donutHoleFiller;
@@ -86,18 +86,16 @@ private CacheSettings BuildCacheSettings()
8686
VaryByParam = VaryByParam
8787
};
8888
}
89-
else
90-
{
91-
var cacheProfile = _cacheSettingsManager.RetrieveOutputCacheProfile(CacheProfile);
9289

93-
return new CacheSettings
94-
{
95-
IsCachingEnabled = _cacheSettingsManager.IsCachingEnabledGlobally && cacheProfile.Enabled,
96-
Duration = Duration == 0 ? cacheProfile.Duration : Duration,
97-
VaryByCustom = VaryByCustom ?? cacheProfile.VaryByCustom,
98-
VaryByParam = VaryByParam ?? cacheProfile.VaryByParam
99-
};
100-
}
90+
var cacheProfile = _cacheSettingsManager.RetrieveOutputCacheProfile(CacheProfile);
91+
92+
return new CacheSettings
93+
{
94+
IsCachingEnabled = _cacheSettingsManager.IsCachingEnabledGlobally && cacheProfile.Enabled,
95+
Duration = Duration == 0 ? cacheProfile.Duration : Duration,
96+
VaryByCustom = VaryByCustom ?? cacheProfile.VaryByCustom,
97+
VaryByParam = VaryByParam ?? cacheProfile.VaryByParam
98+
};
10199
}
102100
}
103101
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace DevTrends.MvcDonutCaching
4+
{
5+
internal interface IExtendedOutputCacheManager : IOutputCacheManager
6+
{
7+
void AddItem(string key, object entry, DateTime utcExpiry);
8+
string GetItem(string key);
9+
}
10+
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
1+
using System.Web.Routing;
52

63
namespace DevTrends.MvcDonutCaching
74
{
85
public interface IOutputCacheManager
96
{
10-
void AddItem(string key, object entry, DateTime utcExpiry);
11-
string GetItem(string key);
7+
void RemoveItem(string controllerName, string actionName);
8+
void RemoveItem(string controllerName, string actionName, object routeValues);
9+
void RemoveItem(string controllerName, string actionName, RouteValueDictionary routeValues);
10+
void RemoveItems();
11+
void RemoveItems(string controllerName);
12+
void RemoveItems(string controllerName, string actionName);
1213
}
1314
}

DevTrends.MvcDonutCaching/KeyBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ public string BuildKey(string controllerName, string actionName, RouteValueDicti
2323

2424
if (controllerName != null)
2525
{
26-
builder.Append(controllerName.ToLowerInvariant());
26+
builder.AppendFormat("{0}.", controllerName.ToLowerInvariant());
2727
}
2828

2929
if (actionName != null)
3030
{
31-
builder.AppendFormat(".{0}", actionName.ToLowerInvariant());
31+
builder.AppendFormat("{0}#", actionName.ToLowerInvariant());
3232
}
3333

3434
if (routeValues != null)
3535
{
3636
foreach (var routeValue in routeValues)
3737
{
38-
builder.AppendFormat("#{0}={1}", routeValue.Key.ToLowerInvariant(), routeValue.Value.ToString().ToLowerInvariant());
38+
builder.AppendFormat("{0}={1}#", routeValue.Key.ToLowerInvariant(), routeValue.Value.ToString().ToLowerInvariant());
3939
}
4040
}
4141

DevTrends.MvcDonutCaching/OutputCacheManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace DevTrends.MvcDonutCaching
88
{
9-
public class OutputCacheManager : IOutputCacheManager
9+
public class OutputCacheManager : IExtendedOutputCacheManager
1010
{
1111
private readonly OutputCacheProvider _outputCacheProvider;
1212
private readonly IKeyBuilder _keyBuilder;

DevTrends.MvcDonutCaching/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
[assembly: AssemblyCulture("")]
1212
[assembly: ComVisible(false)]
1313
[assembly: Guid("ebcc3291-f04a-4511-b7eb-ddf57a74ada9")]
14-
[assembly: AssemblyVersion("1.0.0.0")]
15-
[assembly: AssemblyFileVersion("1.0.0.0")]
14+
[assembly: AssemblyVersion("1.0.1")]
15+
[assembly: AssemblyFileVersion("1.0.1")]

0 commit comments

Comments
 (0)