mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#5309: Updated OutputCacheFilter to include a check for the OutputCacheAttribute.Location value.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user