diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Handlers/CacheItemInvalidationHandler.cs b/src/Orchard.Web/Modules/Orchard.OutputCache/Handlers/CacheItemInvalidationHandler.cs new file mode 100644 index 00000000000..0850dd716b5 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Handlers/CacheItemInvalidationHandler.cs @@ -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((context, part) => Invalidate(part)); + OnRemoved((context, part) => Invalidate(part)); + OnDestroyed((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(); + if (commonPart != null) { + if (commonPart.Container != null) { + _cacheService.RemoveByTag(commonPart.Container.Id.ToString(CultureInfo.InvariantCulture)); + } + } + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Handlers/CacheSettingsPartHandler.cs b/src/Orchard.Web/Modules/Orchard.OutputCache/Handlers/CacheSettingsPartHandler.cs index 6a0eff1f38e..423d387adc1 100644 --- a/src/Orchard.Web/Modules/Orchard.OutputCache/Handlers/CacheSettingsPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Handlers/CacheSettingsPartHandler.cs @@ -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 @@ public class CacheSettingsPartHandler : ContentHandler { part.DefaultCacheGraceTime = 60; }); - // Evict cached content when updated, removed or destroyed. - OnPublished((context, part) => Invalidate(part)); - OnRemoved((context, part) => Invalidate(part)); - OnDestroyed((context, part) => Invalidate(part)); - OnExporting(ExportRouteSettings); OnImporting(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(); - 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", diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Orchard.OutputCache.csproj b/src/Orchard.Web/Modules/Orchard.OutputCache/Orchard.OutputCache.csproj index 3d4a6cf67c2..028482a786b 100644 --- a/src/Orchard.Web/Modules/Orchard.OutputCache/Orchard.OutputCache.csproj +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Orchard.OutputCache.csproj @@ -107,6 +107,7 @@ + @@ -208,4 +209,4 @@ - \ No newline at end of file +