Orchard/src/Orchard.Web/Modules/Orchard.SecureSocketsLayer/Handlers/SslSettingsPartHandler.cs
Hermes Sbicego d8bb23a4c4
Update SslSettingsPartHandler.cs (#8715)
Adds the OnUpdated handler in order to Invalidate the cache of the settings
2023-07-21 08:03:42 +02:00

45 lines
1.5 KiB
C#

using Orchard.ContentManagement;
using Orchard.Data;
using Orchard.ContentManagement.Handlers;
using Orchard.Localization;
using Orchard.SecureSocketsLayer.Models;
using Orchard.Caching;
namespace Orchard.SecureSocketsLayer.Handlers {
public class SslSettingsPartHandler : ContentHandler {
private readonly ISignals _signals;
public SslSettingsPartHandler(ISignals signals) {
_signals = signals;
T = NullLocalizer.Instance;
Filters.Add(new ActivatingFilter<SslSettingsPart>("Site"));
// Evict cached content when updated, removed or destroyed.
OnUpdated<SslSettingsPart>((context, part) => Invalidate(part));
OnPublished<SslSettingsPart>((context, part) => Invalidate(part));
OnRemoved<SslSettingsPart>((context, part) => Invalidate(part));
OnDestroyed<SslSettingsPart>((context, part) => Invalidate(part));
}
public Localizer T { get; set; }
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
if (context.ContentItem.ContentType != "Site")
return;
base.GetItemMetadata(context);
context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("SSL")) {
Id = "Ssl",
Position = "2"
});
}
private void Invalidate(SslSettingsPart content) {
_signals.Trigger($"SslSettingsPart_{content.Id}");
_signals.Trigger("SslSettingsPart_EvictAll");
}
}
}