2024-10-15 12:02:48 +02:00
|
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
|
using Umbraco.Cms.Core.Events;
|
|
|
|
|
|
using Umbraco.Cms.Core.Notifications;
|
|
|
|
|
|
using Umbraco.Cms.Core.PublishedCache;
|
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Infrastructure.HybridCache.NotificationHandlers;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Rebuilds the database cache if required when the serializer changes
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class HybridCacheStartupNotificationHandler : INotificationAsyncHandler<UmbracoApplicationStartingNotification>
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IDatabaseCacheRebuilder _databaseCacheRebuilder;
|
|
|
|
|
|
private readonly IRuntimeState _runtimeState;
|
|
|
|
|
|
|
|
|
|
|
|
public HybridCacheStartupNotificationHandler(IDatabaseCacheRebuilder databaseCacheRebuilder, IRuntimeState runtimeState)
|
|
|
|
|
|
{
|
|
|
|
|
|
_databaseCacheRebuilder = databaseCacheRebuilder;
|
|
|
|
|
|
_runtimeState = runtimeState;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-22 15:26:04 +02:00
|
|
|
|
public async Task HandleAsync(UmbracoApplicationStartingNotification notification, CancellationToken cancellationToken)
|
2024-10-15 12:02:48 +02:00
|
|
|
|
{
|
2025-07-22 15:26:04 +02:00
|
|
|
|
if (_runtimeState.Level <= RuntimeLevel.Install)
|
2024-10-15 12:02:48 +02:00
|
|
|
|
{
|
2025-07-22 15:26:04 +02:00
|
|
|
|
return;
|
2024-10-15 12:02:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-22 15:26:04 +02:00
|
|
|
|
await _databaseCacheRebuilder.RebuildDatabaseCacheIfSerializerChangedAsync();
|
2024-10-15 12:02:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|