diff --git a/.gitignore b/.gitignore index d8fcbee..8c84a70 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ _[Rr]esharper.* nuget/lib/ # Doxygen -doc/* \ No newline at end of file +doc/* +/.nuget diff --git a/DevTrends.MvcDonutCaching.Demo/Controllers/HomeController.cs b/DevTrends.MvcDonutCaching.Demo/Controllers/HomeController.cs index 91e45ff..c666826 100644 --- a/DevTrends.MvcDonutCaching.Demo/Controllers/HomeController.cs +++ b/DevTrends.MvcDonutCaching.Demo/Controllers/HomeController.cs @@ -40,6 +40,7 @@ public ActionResult SimpleDonutTwo() public ActionResult ExpireSimpleDonutCache() { OutputCacheManager.RemoveItem("Home", "Simple"); + OutputCacheManager.RemoveItem("Home", "CachedHeaders"); return Content("OK", "text/plain"); } @@ -56,5 +57,14 @@ public ActionResult TestIssue23() { return View(); } + + + [DonutOutputCache(Duration = 60, CachedHeaders = "x-cache-me")] + public ActionResult CachedHeaders() { + Response.AppendHeader("x-cache-me", Guid.NewGuid().ToString()); + return Json(new { + CacheTime = DateTime.Now + }, JsonRequestBehavior.AllowGet); + } } } diff --git a/DevTrends.MvcDonutCaching.Demo/MvcDonutCaching.Demo.csproj b/DevTrends.MvcDonutCaching.Demo/MvcDonutCaching.Demo.csproj index 694c19e..381d625 100644 --- a/DevTrends.MvcDonutCaching.Demo/MvcDonutCaching.Demo.csproj +++ b/DevTrends.MvcDonutCaching.Demo/MvcDonutCaching.Demo.csproj @@ -21,6 +21,8 @@ + ..\ + true true @@ -54,25 +56,25 @@ False ..\packages\Artem.XmlProviders40.4.0\lib\Artem.Web.Security.Xml.dll - + False - ..\packages\Autofac.3.3.1\lib\net40\Autofac.dll + ..\packages\Autofac.3.5.2\lib\net40\Autofac.dll - + False - ..\packages\Autofac.Mvc5.3.2.1\lib\net45\Autofac.Integration.Mvc.dll + ..\packages\Autofac.Mvc5.3.3.4\lib\net45\Autofac.Integration.Mvc.dll - + False - ..\packages\Glimpse.AspNet.1.9.0\lib\net45\Glimpse.AspNet.dll + ..\packages\Glimpse.AspNet.1.9.2\lib\net45\Glimpse.AspNet.dll False ..\packages\Glimpse.Autofac.0.2.4\lib\net40\Glimpse.Autofac.dll - + False - ..\packages\Glimpse.1.8.5\lib\net45\Glimpse.Core.dll + ..\packages\Glimpse.1.8.6\lib\net45\Glimpse.Core.dll False @@ -85,7 +87,7 @@ False - ..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll @@ -99,32 +101,32 @@ False - ..\packages\Microsoft.AspNet.WebPages.3.1.2\lib\net45\System.Web.Helpers.dll + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll - + False - ..\packages\Microsoft.AspNet.Mvc.5.1.2\lib\net45\System.Web.Mvc.dll + ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll - + + False ..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll - True False - ..\packages\Microsoft.AspNet.Razor.3.1.2\lib\net45\System.Web.Razor.dll + ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll False - ..\packages\Microsoft.AspNet.WebPages.3.1.2\lib\net45\System.Web.WebPages.dll + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll False - ..\packages\Microsoft.AspNet.WebPages.3.1.2\lib\net45\System.Web.WebPages.Deployment.dll + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll False - ..\packages\Microsoft.AspNet.WebPages.3.1.2\lib\net45\System.Web.WebPages.Razor.dll + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll @@ -160,9 +162,9 @@ - - - + + + Designer @@ -178,8 +180,8 @@ - + @@ -219,9 +221,7 @@ - - Designer - + 10.0 @@ -252,6 +252,13 @@ + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + -
- +
+ + + + @@ -50,34 +53,34 @@ --> - - - - + + + + - - - - + + + + - - - - + + + + - - - - - - - - + + + + + + + + - + + + + + + + + + @@ -103,33 +114,25 @@ - - - - - - - - - + - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + \ No newline at end of file diff --git a/DevTrends.MvcDonutCaching.Demo/packages.config b/DevTrends.MvcDonutCaching.Demo/packages.config index 5e3e19a..3efc60f 100644 --- a/DevTrends.MvcDonutCaching.Demo/packages.config +++ b/DevTrends.MvcDonutCaching.Demo/packages.config @@ -2,19 +2,19 @@ - - - - + + + + - - + + - + - + - + \ No newline at end of file diff --git a/DevTrends.MvcDonutCaching/CacheItem.cs b/DevTrends.MvcDonutCaching/CacheItem.cs index 8a87772..fe78c69 100644 --- a/DevTrends.MvcDonutCaching/CacheItem.cs +++ b/DevTrends.MvcDonutCaching/CacheItem.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Runtime.Serialization; namespace DevTrends.MvcDonutCaching @@ -23,5 +24,14 @@ public class CacheItem /// [DataMember(Order = 2)] public string Content { get; set; } + + /// + /// Gets or sets the headers to be cached. + /// + /// + /// The content. + /// + [DataMember(Order = 3)] + public KeyValuePair[] CachedHeaders { get; set; } } } diff --git a/DevTrends.MvcDonutCaching/CacheSettings.cs b/DevTrends.MvcDonutCaching/CacheSettings.cs index 377a2a4..09cf688 100644 --- a/DevTrends.MvcDonutCaching/CacheSettings.cs +++ b/DevTrends.MvcDonutCaching/CacheSettings.cs @@ -60,6 +60,12 @@ public class CacheSettings /// public OutputCacheOptions Options { get; set; } + /// + /// Gets or sets the headers to be cached. + /// Seperated with ";" + /// + public string[] CachedHeaders { get; set; } + /// /// Gets a value indicating whether the server caching is enabled. /// diff --git a/DevTrends.MvcDonutCaching/CacheSettingsManager.cs b/DevTrends.MvcDonutCaching/CacheSettingsManager.cs index dae2377..dfc0bcb 100644 --- a/DevTrends.MvcDonutCaching/CacheSettingsManager.cs +++ b/DevTrends.MvcDonutCaching/CacheSettingsManager.cs @@ -1,5 +1,4 @@ -using System; -using System.Configuration; +using System.Configuration; using System.Diagnostics; using System.Security; using System.Web; diff --git a/DevTrends.MvcDonutCaching/DonutOutputCacheAttribute.cs b/DevTrends.MvcDonutCaching/DonutOutputCacheAttribute.cs index 1d78bd8..84438ac 100644 --- a/DevTrends.MvcDonutCaching/DonutOutputCacheAttribute.cs +++ b/DevTrends.MvcDonutCaching/DonutOutputCacheAttribute.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.UI; @@ -21,6 +23,7 @@ public class DonutOutputCacheAttribute : ActionFilterAttribute, IExceptionFilter // Private private bool? _noStore; private OutputCacheOptions? _options; + private string[] _cachedHeaders; public DonutOutputCacheAttribute() : this(new KeyBuilder()) { } @@ -110,6 +113,21 @@ public bool NoStore } } + /// + /// Gets or sets the headers to be cached. + /// Seperated with ";" + /// + public string CachedHeaders { + get { return _cachedHeaders != null ? string.Join(";", _cachedHeaders) : null; } + set { + if (value == null) { + return; + } + + _cachedHeaders = value.Split(new []{';'}, StringSplitOptions.RemoveEmptyEntries); + } + } + /// /// Get or sets the for this attributes. Specifying a value here will /// make the value ignored. @@ -175,6 +193,12 @@ public override void OnActionExecuting(ActionExecutingContext filterContext) Content = DonutHoleFiller.ReplaceDonutHoleContent(cachedItem.Content, filterContext, CacheSettings.Options), ContentType = cachedItem.ContentType }; + + if (cachedItem.CachedHeaders != null) { + foreach (var cachedHeader in cachedItem.CachedHeaders) { + filterContext.HttpContext.Response.Headers[cachedHeader.Key] = cachedHeader.Value; + } + } } } @@ -213,6 +237,14 @@ public override void OnActionExecuting(ActionExecutingContext filterContext) ContentType = filterContext.HttpContext.Response.ContentType }; + // Cache headers from response + if (CacheSettings.CachedHeaders != null) { + cacheItem.CachedHeaders = CacheSettings.CachedHeaders + .Where(header => filterContext.HttpContext.Response.Headers.AllKeys.Contains(header)) + .Select(header => new KeyValuePair(header, filterContext.HttpContext.Response.Headers[header])) + .ToArray(); + } + filterContext.HttpContext.Response.Write( DonutHoleFiller.RemoveDonutHoleWrappers(cacheItem.Content, filterContext, CacheSettings.Options) ); @@ -268,6 +300,7 @@ protected CacheSettings BuildCacheSettings() Location = (int)Location == -1 ? OutputCacheLocation.Server : Location, NoStore = NoStore, Options = Options, + CachedHeaders = _cachedHeaders }; } else @@ -283,6 +316,7 @@ protected CacheSettings BuildCacheSettings() Location = (int)Location == -1 ? ((int)cacheProfile.Location == -1 ? OutputCacheLocation.Server : cacheProfile.Location) : Location, NoStore = _noStore.HasValue ? _noStore.Value : cacheProfile.NoStore, Options = Options, + CachedHeaders = _cachedHeaders }; } diff --git a/DevTrends.MvcDonutCaching/MvcDonutCaching.csproj b/DevTrends.MvcDonutCaching/MvcDonutCaching.csproj index b8828f5..5fb6275 100644 --- a/DevTrends.MvcDonutCaching/MvcDonutCaching.csproj +++ b/DevTrends.MvcDonutCaching/MvcDonutCaching.csproj @@ -10,8 +10,11 @@ Properties DevTrends.MvcDonutCaching DevTrends.MvcDonutCaching - v4.0 + v4.5 512 + + ..\ + true true @@ -21,6 +24,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -29,6 +33,7 @@ TRACE prompt 4 + false ..\nuget\lib\net40\ @@ -38,6 +43,7 @@ AnyCPU prompt ..\nuget\lib\net40\DevTrends.MvcDonutCaching.XML + false true @@ -47,8 +53,13 @@ AnyCPU prompt MinimumRecommendedRules.ruleset + false + + True + ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + @@ -56,8 +67,31 @@ - + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll + + + False + ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll + + + False + ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll + + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll + + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll + + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll + @@ -95,7 +129,17 @@ + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + +