diff --git a/src/Microsoft.AspNetCore.Mvc.Core/CacheProfile.cs b/src/Microsoft.AspNetCore.Mvc.Core/CacheProfile.cs
index 92422c2ac5..caef771693 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/CacheProfile.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/CacheProfile.cs
@@ -11,7 +11,7 @@ public class CacheProfile
///
/// Gets or sets the duration in seconds for which the response is cached.
/// If this property is set to a non null value,
- /// the "max-age" in "Cache-control" header is set in the
+ /// the "max-age" in "Cache-control" header is set in the
/// .
///
public int? Duration { get; set; }
@@ -36,5 +36,10 @@ public class CacheProfile
/// Gets or sets the value for the Vary header in .
///
public string VaryByHeader { get; set; }
+
+ ///
+ /// TODO:
+ ///
+ public string[] VaryByQueryKeys { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseCacheFilter.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseCacheFilter.cs
index b27ec02e93..87ad29920e 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseCacheFilter.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseCacheFilter.cs
@@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Core;
using Microsoft.AspNetCore.Mvc.Filters;
+using Microsoft.AspNetCore.ResponseCaching;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Mvc.Internal
@@ -21,6 +22,7 @@ public class ResponseCacheFilter : IActionFilter, IResponseCacheFilter
private ResponseCacheLocation? _cacheLocation;
private bool? _cacheNoStore;
private string _cacheVaryByHeader;
+ private string[] _cacheVaryByQueryKey;
///
/// Creates a new instance of
@@ -73,6 +75,15 @@ public string VaryByHeader
set { _cacheVaryByHeader = value; }
}
+ ///
+ /// TODO:
+ ///
+ public string[] VaryByQueryKeys
+ {
+ get { return _cacheVaryByQueryKey ?? _cacheProfile.VaryByQueryKeys; }
+ set { _cacheVaryByQueryKey = value; }
+ }
+
///
public void OnActionExecuting(ActionExecutingContext context)
{
@@ -110,6 +121,16 @@ public void OnActionExecuting(ActionExecutingContext context)
headers[HeaderNames.Vary] = VaryByHeader;
}
+ if (VaryByQueryKeys != null)
+ {
+ var responseCacheFeature = context.HttpContext.GetResponseCacheFeature(); // TODO: replace this call
+ if (responseCacheFeature == null)
+ {
+ throw new InvalidOperationException($"The response cache middleware must be added when using the {nameof(VaryByQueryKeys)} feature.");
+ }
+ responseCacheFeature.VaryByQueryKeys = VaryByQueryKeys;
+ }
+
if (NoStore)
{
headers[HeaderNames.CacheControl] = "no-store";
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs
index 9bddb6a66b..ccc2128f66 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs
@@ -77,6 +77,11 @@ public bool NoStore
///
public string VaryByHeader { get; set; }
+ ///
+ /// TODO:
+ ///
+ public string[] VaryByQueryKeys { get; set; }
+
///
/// Gets or sets the value of the cache profile name.
///
@@ -117,6 +122,7 @@ public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
_noStore = _noStore ?? selectedProfile?.NoStore;
_location = _location ?? selectedProfile?.Location;
VaryByHeader = VaryByHeader ?? selectedProfile?.VaryByHeader;
+ VaryByQueryKeys = VaryByQueryKeys ?? selectedProfile?.VaryByQueryKeys;
// ResponseCacheFilter cannot take any null values. Hence, if there are any null values,
// the properties convert them to their defaults and are passed on.
@@ -125,7 +131,8 @@ public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
Duration = _duration,
Location = _location,
NoStore = _noStore,
- VaryByHeader = VaryByHeader
+ VaryByHeader = VaryByHeader,
+ VaryByQueryKeys = VaryByQueryKeys
});
}
}
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/project.json b/src/Microsoft.AspNetCore.Mvc.Core/project.json
index 13d0fc38e8..404c51453c 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/project.json
+++ b/src/Microsoft.AspNetCore.Mvc.Core/project.json
@@ -24,6 +24,7 @@
"Microsoft.AspNetCore.Hosting.Abstractions": "1.1.0-*",
"Microsoft.AspNetCore.Http": "1.1.0-*",
"Microsoft.AspNetCore.Mvc.Abstractions": "1.1.0-*",
+ "Microsoft.AspNetCore.ResponseCaching": "0.1.0-*",
"Microsoft.AspNetCore.Routing": "1.1.0-*",
"Microsoft.AspNetCore.Routing.DecisionTree.Sources": {
"type": "build",
diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ResponseCacheFilterTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ResponseCacheFilterTest.cs
index 4e8248266d..ae43492c64 100644
--- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ResponseCacheFilterTest.cs
+++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ResponseCacheFilterTest.cs
@@ -6,8 +6,10 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
+using Microsoft.AspNetCore.ResponseCaching;
using Microsoft.AspNetCore.Routing;
using Xunit;
+using System.Linq;
namespace Microsoft.AspNetCore.Mvc.Internal
{
@@ -210,7 +212,7 @@ public void OnActionExecuting_DoesNotSetLocationOrDuration_IfNoStoreIsSet(
Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]);
}
- public static IEnumerable