Merge commit '94d525d88f713b36419f28bfda4d82ee68637d83' into v9/dev
# Conflicts: # build/NuSpecs/UmbracoCms.Web.nuspec # src/Umbraco.Core/Composing/Current.cs # src/Umbraco.Core/Persistence/NPocoDatabaseExtensions-Bulk.cs # src/Umbraco.Core/Runtime/CoreRuntime.cs # src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs # src/Umbraco.Infrastructure/Persistence/NPocoDatabaseExtensions.cs # src/Umbraco.Infrastructure/Persistence/UmbracoDatabase.cs # src/Umbraco.Persistence.SqlCe/SqlCeSyntaxProvider.cs # src/Umbraco.PublishedCache.NuCache/DataSource/BTree.cs # src/Umbraco.PublishedCache.NuCache/DataSource/ContentCacheDataModel.cs # src/Umbraco.PublishedCache.NuCache/DataSource/ContentCacheDataSerializationResult.cs # src/Umbraco.PublishedCache.NuCache/DataSource/ContentCacheDataSerializerEntityType.cs # src/Umbraco.PublishedCache.NuCache/DataSource/ContentData.cs # src/Umbraco.PublishedCache.NuCache/DataSource/ContentNestedData.cs # src/Umbraco.PublishedCache.NuCache/DataSource/CultureVariation.cs # src/Umbraco.PublishedCache.NuCache/DataSource/IContentCacheDataSerializer.cs # src/Umbraco.PublishedCache.NuCache/DataSource/IContentCacheDataSerializerFactory.cs # src/Umbraco.PublishedCache.NuCache/DataSource/IDictionaryOfPropertyDataSerializer.cs # src/Umbraco.PublishedCache.NuCache/DataSource/JsonContentNestedDataSerializer.cs # src/Umbraco.PublishedCache.NuCache/DataSource/JsonContentNestedDataSerializerFactory.cs # src/Umbraco.PublishedCache.NuCache/DataSource/LazyCompressedString.cs # src/Umbraco.PublishedCache.NuCache/DataSource/MsgPackContentNestedDataSerializer.cs # src/Umbraco.PublishedCache.NuCache/DataSource/MsgPackContentNestedDataSerializerFactory.cs # src/Umbraco.PublishedCache.NuCache/DataSource/PropertyData.cs # src/Umbraco.PublishedCache.NuCache/NuCacheSerializerComponent.cs # src/Umbraco.PublishedCache.NuCache/NuCacheSerializerComposer.cs # src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs # src/Umbraco.Tests/App.config # src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs # src/Umbraco.Tests/PublishedContent/NuCacheTests.cs # src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/da.xml # src/Umbraco.Web.UI/web.Template.Debug.config # src/Umbraco.Web.UI/web.Template.config # src/Umbraco.Web/Composing/ModuleInjector.cs # src/Umbraco.Web/Editors/NuCacheStatusController.cs # src/Umbraco.Web/PublishedCache/NuCache/DataSource/ContentNestedData.cs # src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs # src/Umbraco.Web/PublishedCache/NuCache/NuCacheComposer.cs # src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs # src/Umbraco.Web/Runtime/WebRuntime.cs
This commit is contained in:
67
src/Umbraco.PublishedCache.NuCache/NuCacheStartupHandler.cs
Normal file
67
src/Umbraco.PublishedCache.NuCache/NuCacheStartupHandler.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Logging;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
using Umbraco.Cms.Core.PublishedCache;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.PublishedCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Rebuilds the database cache if required when the serializer changes
|
||||
/// </summary>
|
||||
public class NuCacheStartupHandler : INotificationHandler<UmbracoApplicationStartingNotification>
|
||||
{
|
||||
// TODO: Eventually we should kill this since at some stage we shouldn't even support JSON since we know
|
||||
// this is faster.
|
||||
|
||||
internal const string Nucache_Serializer_Key = "Umbraco.Web.PublishedCache.NuCache.Serializer";
|
||||
private const string JSON_SERIALIZER_VALUE = "JSON";
|
||||
private readonly IPublishedSnapshotService _service;
|
||||
private readonly IKeyValueService _keyValueService;
|
||||
private readonly IProfilingLogger _profilingLogger;
|
||||
private readonly ILogger<NuCacheStartupHandler> _logger;
|
||||
|
||||
public NuCacheStartupHandler(
|
||||
IPublishedSnapshotService service,
|
||||
IKeyValueService keyValueService,
|
||||
IProfilingLogger profilingLogger,
|
||||
ILogger<NuCacheStartupHandler> logger)
|
||||
{
|
||||
_service = service;
|
||||
_keyValueService = keyValueService;
|
||||
_profilingLogger = profilingLogger;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Handle(UmbracoApplicationStartingNotification notification)
|
||||
=> RebuildDatabaseCacheIfSerializerChanged();
|
||||
|
||||
private void RebuildDatabaseCacheIfSerializerChanged()
|
||||
{
|
||||
var serializer = ConfigurationManager.AppSettings[Nucache_Serializer_Key];
|
||||
var currentSerializer = _keyValueService.GetValue(Nucache_Serializer_Key);
|
||||
|
||||
if (currentSerializer == null)
|
||||
{
|
||||
currentSerializer = JSON_SERIALIZER_VALUE;
|
||||
}
|
||||
if (serializer == null)
|
||||
{
|
||||
serializer = JSON_SERIALIZER_VALUE;
|
||||
}
|
||||
|
||||
if (serializer != currentSerializer)
|
||||
{
|
||||
_logger.LogWarning("Database NuCache was serialized using {CurrentSerializer}. Currently configured NuCache serializer {Serializer}. Rebuilding Nucache", currentSerializer, serializer);
|
||||
|
||||
using (_profilingLogger.TraceDuration<NuCacheStartupHandler>($"Rebuilding NuCache database with {currentSerializer} serializer"))
|
||||
{
|
||||
_service.Rebuild();
|
||||
_keyValueService.SetValue(Nucache_Serializer_Key, serializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user