Skip to content

Commit 2cd3ea7

Browse files
author
DevTrends
committed
Added Html.RenderAction support
Added NoStore support Changed priority order of POST/GET values Made CacheItem serialisable - for Memcached
1 parent 7492953 commit 2cd3ea7

12 files changed

+164
-46
lines changed

DevTrends.MvcDonutCaching/ActionSettingsSerialiser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Runtime.Serialization;
33
using System.Text;
44
using System.Web.Routing;
5-
using System.Web.Script.Serialization;
65

76
namespace DevTrends.MvcDonutCaching
87
{

DevTrends.MvcDonutCaching/CacheHeadersHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public void SetCacheHeaders(HttpResponseBase response, CacheSettings settings)
2929
response.Cache.SetExpires(DateTime.Now.AddSeconds(settings.Duration));
3030
response.Cache.SetMaxAge(new TimeSpan(0, 0, settings.Duration));
3131
}
32+
33+
if (settings.NoStore)
34+
{
35+
response.Cache.SetNoStore();
36+
}
3237
}
3338
}
3439
}

DevTrends.MvcDonutCaching/CacheItem.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-

1+
using System;
2+
23
namespace DevTrends.MvcDonutCaching
34
{
5+
[Serializable]
46
public class CacheItem
57
{
68
public string Content { get; set; }

DevTrends.MvcDonutCaching/CacheSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ public class CacheSettings
99
public string VaryByParam { get; set; }
1010
public string VaryByCustom { get; set; }
1111
public OutputCacheLocation Location { get; set; }
12+
public bool NoStore { get; set; }
1213

1314
public bool IsServerCachingEnabled
1415
{
1516
get
1617
{
1718
return IsCachingEnabled && Duration > 0 && (Location == OutputCacheLocation.Any ||
1819
Location == OutputCacheLocation.Server ||
19-
Location == OutputCacheLocation.ServerAndClient);
20+
Location == OutputCacheLocation.ServerAndClient);
2021
}
2122
}
2223
}

DevTrends.MvcDonutCaching/DonutHoleFiller.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public string RemoveDonutHoleWrappers(string content, ControllerContext filterCo
3030
return content;
3131
}
3232

33-
return DonutHoles.Replace(content, new MatchEvaluator(match => match.Groups[2].Value));
33+
return DonutHoles.Replace(content, match => match.Groups[2].Value);
3434
}
3535

3636
public string ReplaceDonutHoleContent(string content, ControllerContext filterContext)
@@ -40,12 +40,12 @@ public string ReplaceDonutHoleContent(string content, ControllerContext filterCo
4040
return content;
4141
}
4242

43-
return DonutHoles.Replace(content, new MatchEvaluator(match =>
43+
return DonutHoles.Replace(content, match =>
4444
{
4545
var actionSettings = _actionSettingsSerialiser.Deserialise(match.Groups[1].Value);
4646

4747
return InvokeAction(filterContext.Controller, actionSettings.ActionName, actionSettings.ControllerName, actionSettings.RouteValues);
48-
}));
48+
});
4949
}
5050

5151
private static string InvokeAction(ControllerBase controller, string actionName, string controllerName, RouteValueDictionary routeValues)
@@ -58,4 +58,4 @@ private static string InvokeAction(ControllerBase controller, string actionName,
5858
return htmlHelper.Action(actionName, controllerName, routeValues).ToString();
5959
}
6060
}
61-
}
61+
}

DevTrends.MvcDonutCaching/DonutOutputCacheAttribute.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@ public class DonutOutputCacheAttribute : ActionFilterAttribute, IExceptionFilter
1616
private readonly ICacheSettingsManager _cacheSettingsManager;
1717
private readonly ICacheHeadersHelper _cacheHeadersHelper;
1818

19+
private bool? _noStore;
1920
private CacheSettings _cacheSettings;
2021

2122
public int Duration { get; set; }
2223
public string VaryByParam { get; set; }
2324
public string VaryByCustom { get; set; }
2425
public string CacheProfile { get; set; }
2526
public OutputCacheLocation Location { get; set; }
27+
28+
public bool NoStore
29+
{
30+
get { return _noStore ?? false; }
31+
set { _noStore = value; }
32+
}
2633

2734
public DonutOutputCacheAttribute()
2835
{
@@ -133,7 +140,8 @@ private CacheSettings BuildCacheSettings()
133140
Duration = Duration,
134141
VaryByCustom = VaryByCustom,
135142
VaryByParam = VaryByParam,
136-
Location = (int)Location == -1 ? OutputCacheLocation.Server : Location
143+
Location = (int)Location == -1 ? OutputCacheLocation.Server : Location,
144+
NoStore = NoStore
137145
};
138146
}
139147
else
@@ -146,7 +154,8 @@ private CacheSettings BuildCacheSettings()
146154
Duration = Duration == -1 ? cacheProfile.Duration : Duration,
147155
VaryByCustom = VaryByCustom ?? cacheProfile.VaryByCustom,
148156
VaryByParam = VaryByParam ?? cacheProfile.VaryByParam,
149-
Location = (int)Location == -1 ? ((int)cacheProfile.Location == -1 ? OutputCacheLocation.Server : cacheProfile.Location) : Location
157+
Location = (int)Location == -1 ? ((int)cacheProfile.Location == -1 ? OutputCacheLocation.Server : cacheProfile.Location) : Location,
158+
NoStore = _noStore.HasValue ? _noStore.Value : cacheProfile.NoStore
150159
};
151160
}
152161

0 commit comments

Comments
 (0)