-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V15: Reimplement cache startup handler (#17279)
* Reimplement cache startup handler * Remove duplicate handle * Fixed missing scope and ordering of notifications * formatting --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk>
- Loading branch information
Showing
4 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ | |
public interface IDatabaseCacheRebuilder | ||
{ | ||
void Rebuild(); | ||
|
||
void RebuildDatabaseCacheIfSerializerChanged(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
....PublishedCache.HybridCache/NotificationHandlers/HybridCacheStartupNotificationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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; | ||
} | ||
|
||
public Task HandleAsync(UmbracoApplicationStartingNotification notification, CancellationToken cancellationToken) | ||
{ | ||
if (_runtimeState.Level > RuntimeLevel.Install) | ||
{ | ||
_databaseCacheRebuilder.RebuildDatabaseCacheIfSerializerChanged(); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |