Skip to content

Commit 03e3c3c

Browse files
Make sure ContentOfTypeCacheRefresherNotificationHandlerBase implements IDistributedCacheNotificationHandler and that it handles the root nodes of a refresh call
1 parent 70cb14b commit 03e3c3c

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/Umbraco.Commerce.Checkout/Events/ContentOfTypeCacheRefresherNotificationHandlerBase.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public abstract class ContentOfTypeCacheRefresherNotificationHandlerBase(
1818
IDocumentNavigationQueryService documentNavigationQueryService,
1919
IContentService contentService,
2020
IIdKeyMap keyMap,
21-
IServerRoleAccessor serverRoleAccessor) : INotificationAsyncHandler<ContentCacheRefresherNotification>
21+
IServerRoleAccessor serverRoleAccessor) : INotificationAsyncHandler<ContentCacheRefresherNotification>, IDistributedCacheNotificationHandler
2222
{
2323
protected abstract string ContentTypeAlias { get; }
2424
protected abstract Task HandleContentOfTypeAsync(IContent content);
@@ -57,6 +57,18 @@ public async Task HandleAsync(ContentCacheRefresherNotification notification, Ca
5757
{
5858
// Branch refresh
5959
Guid rootNodeKey = payload.Key ?? keyMap.GetKeyForId(payload.Id, UmbracoObjectTypes.Document).ResultOr(Guid.Empty);
60+
61+
// Handle the branch root
62+
if (rootNodeKey != Guid.Empty)
63+
{
64+
IContent? content = contentService.GetById(rootNodeKey);
65+
if (content != null && content.ContentType.Alias == ContentTypeAlias)
66+
{
67+
await HandleContentOfTypeAsync(content);
68+
}
69+
}
70+
71+
// Handle the descendants
6072
if (rootNodeKey != Guid.Empty && documentNavigationQueryService.TryGetDescendantsKeysOfType(rootNodeKey, ContentTypeAlias, out IEnumerable<Guid> keys))
6173
{
6274
foreach (Guid key in keys)
@@ -71,6 +83,20 @@ public async Task HandleAsync(ContentCacheRefresherNotification notification, Ca
7183
}
7284
else if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshAll))
7385
{
86+
// Handle root nodes
87+
if (documentNavigationQueryService.TryGetRootKeysOfType(ContentTypeAlias, out IEnumerable<Guid> rootKeysOfType))
88+
{
89+
foreach (Guid rootKey in rootKeysOfType)
90+
{
91+
IContent? content = contentService.GetById(rootKey);
92+
if (content != null)
93+
{
94+
await HandleContentOfTypeAsync(content);
95+
}
96+
}
97+
}
98+
99+
// Handle descendants
74100
if (documentNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys))
75101
{
76102
foreach (Guid rootKey in rootKeys)

0 commit comments

Comments
 (0)