mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
This commit is contained in:
parent
aa969534a8
commit
fcaaac3489
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,7 @@
|
|||||||
using System;
|
using System.Linq;
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
using Orchard.Core.Common.Models;
|
|
||||||
using Orchard.OutputCache.Models;
|
using Orchard.OutputCache.Models;
|
||||||
using Orchard.OutputCache.Services;
|
using Orchard.OutputCache.Services;
|
||||||
|
|
||||||
@ -23,28 +20,10 @@ namespace Orchard.OutputCache.Handlers {
|
|||||||
part.DefaultCacheGraceTime = 60;
|
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);
|
OnExporting<CacheSettingsPart>(ExportRouteSettings);
|
||||||
OnImporting<CacheSettingsPart>(ImportRouteSettings);
|
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) {
|
private void ExportRouteSettings(ExportContentContext context, CacheSettingsPart part) {
|
||||||
var routes = _cacheService.GetRouteConfigs();
|
var routes = _cacheService.GetRouteConfigs();
|
||||||
var routesElement = new XElement("Routes",
|
var routesElement = new XElement("Routes",
|
||||||
|
@ -107,6 +107,7 @@
|
|||||||
<Content Include="Web.config" />
|
<Content Include="Web.config" />
|
||||||
<Content Include="Scripts\Web.config" />
|
<Content Include="Scripts\Web.config" />
|
||||||
<Content Include="Styles\Web.config" />
|
<Content Include="Styles\Web.config" />
|
||||||
|
<Compile Include="Handlers\CacheItemInvalidationHandler.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Content Include="Module.txt" />
|
<Content Include="Module.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -208,4 +209,4 @@
|
|||||||
</FlavorProperties>
|
</FlavorProperties>
|
||||||
</VisualStudio>
|
</VisualStudio>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user