Merge branch '1.10.x' into dev

# Conflicts:
#	src/Orchard.Web/Modules/Orchard.OutputCache/Orchard.OutputCache.csproj
This commit is contained in:
Sipke Schoorstra
2018-02-22 12:57:32 +01:00
3 changed files with 37 additions and 23 deletions

View File

@@ -0,0 +1,33 @@
using System.Globalization;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Common.Models;
using Orchard.OutputCache.Services;
namespace Orchard.OutputCache.Handlers {
public class CacheItemInvalidationHandler : ContentHandler {
private readonly ICacheService _cacheService;
public CacheItemInvalidationHandler(ICacheService cacheService) {
_cacheService = cacheService;
// Evict cached content when updated, removed or destroyed.
OnPublished<IContent>((context, part) => Invalidate(part));
OnRemoved<IContent>((context, part) => Invalidate(part));
OnDestroyed<IContent>((context, part) => Invalidate(part));
}
private void Invalidate(IContent content) {
// Remove any item tagged with this content item ID.
_cacheService.RemoveByTag(content.ContentItem.Id.ToString(CultureInfo.InvariantCulture));
// Search the cache for containers too.
var commonPart = content.As<CommonPart>();
if (commonPart != null) {
if (commonPart.Container != null) {
_cacheService.RemoveByTag(commonPart.Container.Id.ToString(CultureInfo.InvariantCulture));
}
}
}
}
}

View File

@@ -1,10 +1,7 @@
using System;
using System.Globalization;
using System.Linq;
using System.Linq;
using System.Xml.Linq;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Common.Models;
using Orchard.OutputCache.Models;
using Orchard.OutputCache.Services;
@@ -23,28 +20,10 @@ namespace Orchard.OutputCache.Handlers {
part.DefaultCacheGraceTime = 60;
});
// Evict cached content when updated, removed or destroyed.
OnPublished<IContent>((context, part) => Invalidate(part));
OnRemoved<IContent>((context, part) => Invalidate(part));
OnDestroyed<IContent>((context, part) => Invalidate(part));
OnExporting<CacheSettingsPart>(ExportRouteSettings);
OnImporting<CacheSettingsPart>(ImportRouteSettings);
}
private void Invalidate(IContent content) {
// Remove any item tagged with this content item ID.
_cacheService.RemoveByTag(content.ContentItem.Id.ToString(CultureInfo.InvariantCulture));
// Search the cache for containers too.
var commonPart = content.As<CommonPart>();
if (commonPart != null) {
if (commonPart.Container != null) {
_cacheService.RemoveByTag(commonPart.Container.Id.ToString(CultureInfo.InvariantCulture));
}
}
}
private void ExportRouteSettings(ExportContentContext context, CacheSettingsPart part) {
var routes = _cacheService.GetRouteConfigs();
var routesElement = new XElement("Routes",

View File

@@ -26,6 +26,7 @@
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
<Use64BitIISExpress />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -107,6 +108,7 @@
<Content Include="Web.config" />
<Content Include="Scripts\Web.config" />
<Content Include="Styles\Web.config" />
<Compile Include="Handlers\CacheItemInvalidationHandler.cs" />
<Compile Include="ICachingEventHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Content Include="Module.txt" />
@@ -202,7 +204,7 @@
<IISUrl>
</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>True</UseCustomServer>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>http://orchard.codeplex.com</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>