#5309: Updated OutputCacheFilter to include a check for the OutputCacheAttribute.Location value.

This commit is contained in:
Sipke Schoorstra
2015-05-21 13:47:14 +02:00
parent 8976cc11d1
commit 5f30667df1
3 changed files with 18 additions and 1 deletions

View File

@@ -11,12 +11,14 @@ using System.Threading;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.UI;
using Orchard.Caching;
using Orchard.ContentManagement;
using Orchard.Environment.Configuration;
using Orchard.Logging;
using Orchard.Mvc.Extensions;
using Orchard.Mvc.Filters;
using Orchard.OutputCache.Helpers;
using Orchard.OutputCache.Models;
using Orchard.OutputCache.Services;
using Orchard.Services;
@@ -263,7 +265,7 @@ namespace Orchard.OutputCache.Filters {
var controllerAttributes = filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(OutputCacheAttribute), true);
var outputCacheAttribute = actionAttributes.Concat(controllerAttributes).Cast<OutputCacheAttribute>().FirstOrDefault();
if (outputCacheAttribute != null) {
if (outputCacheAttribute.Duration <= 0 || outputCacheAttribute.NoStore) {
if (outputCacheAttribute.Duration <= 0 || outputCacheAttribute.NoStore || outputCacheAttribute.IsLocationAnyOf(OutputCacheLocation.Downstream, OutputCacheLocation.Client, OutputCacheLocation.None)) {
Logger.Debug("Request for item '{0}' ignored based on OutputCache attribute.", _cacheKey);
return false;
}

View File

@@ -0,0 +1,14 @@
using System.Linq;
using System.Web.Mvc;
using System.Web.UI;
namespace Orchard.OutputCache.Helpers {
public static class OutputCacheAttributeExtensions {
/// <summary>
/// Returns true if the Location of the specified output cache attribute matches any of the specified list of locations.
/// </summary>
public static bool IsLocationAnyOf(this OutputCacheAttribute attribute, params OutputCacheLocation[] locations) {
return locations.Any(x => attribute.Location == x);
}
}
}

View File

@@ -102,6 +102,7 @@
<Compile Include="Handlers\CacheSettingsPartHandler.cs" />
<Compile Include="Handlers\DisplayedContentItemHandler.cs" />
<Compile Include="DatabaseOutputCacheMigrations.cs" />
<Compile Include="Helpers\OutputCacheAttributeExtensions.cs" />
<Compile Include="Migrations.cs" />
<Compile Include="Models\CacheItem.cs" />
<Compile Include="Models\CacheItemRecord.cs" />