mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Merge pull request #5806 from OrchardCMS/issues/5805/outputcachesettings-importexport
Implemented output cache routes import/export.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using System.Globalization;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Common.Models;
|
||||
@@ -22,6 +25,9 @@ namespace Orchard.OutputCache.Handlers {
|
||||
|
||||
// Evict modified routable content when updated.
|
||||
OnPublished<IContent>((context, part) => Invalidate(part));
|
||||
|
||||
OnExporting<CacheSettingsPart>(ExportRouteSettings);
|
||||
OnImporting<CacheSettingsPart>(ImportRouteSettings);
|
||||
}
|
||||
|
||||
private void Invalidate(IContent content) {
|
||||
@@ -36,5 +42,45 @@ namespace Orchard.OutputCache.Handlers {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ExportRouteSettings(ExportContentContext context, CacheSettingsPart part) {
|
||||
var routes = _cacheService.GetRouteConfigs();
|
||||
var routesElement = new XElement("Routes",
|
||||
routes.Select(x => new XElement("Route")
|
||||
.Attr("Key", x.RouteKey)
|
||||
.Attr("Url", x.Url)
|
||||
.Attr("Priority", x.Priority)
|
||||
.Attr("Duration", x.Duration)
|
||||
.Attr("GraceTime", x.GraceTime)
|
||||
.Attr("MaxAge", x.MaxAge)
|
||||
.Attr("FeatureName", x.FeatureName)));
|
||||
|
||||
context.Element(part.PartDefinition.Name).Add(routesElement);
|
||||
}
|
||||
|
||||
private void ImportRouteSettings(ImportContentContext context, CacheSettingsPart part) {
|
||||
var partElement = context.Data.Element(part.PartDefinition.Name);
|
||||
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (partElement == null)
|
||||
return;
|
||||
|
||||
var routesElement = partElement.Element("Routes");
|
||||
|
||||
if (routesElement == null)
|
||||
return;
|
||||
|
||||
var routeConfigs = routesElement.Elements().Select(x => new CacheRouteConfig {
|
||||
RouteKey = x.Attr("Key"),
|
||||
Duration = x.Attr<int?>("Duration"),
|
||||
Priority = x.Attr<int>("Priority"),
|
||||
Url = x.Attr("Url"),
|
||||
MaxAge = x.Attr<int?>("MaxAge"),
|
||||
GraceTime = x.Attr<int?>("GraceTime"),
|
||||
FeatureName = x.Attr("FeatureName")
|
||||
});
|
||||
|
||||
_cacheService.SaveRouteConfigs(routeConfigs);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user