Skip cache refresher operations for content blueprints (#15633)
* Skip cache refresher operations for content blueprints * Fix JsonPayload deserialization error by adding a default constructor and property initializers * Obsolete JsonPayload constructor and update usages
This commit is contained in:
@@ -84,8 +84,8 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
isolatedCache.ClearOfType<IContent>((k, v) => v.Path?.Contains(pathid) ?? false);
|
||||
}
|
||||
|
||||
// if the item is being completely removed, we need to refresh the domains cache if any domain was assigned to the content
|
||||
if (payload.ChangeTypes.HasTypesAny(TreeChangeTypes.Remove))
|
||||
// if the item is not a blueprint and is being completely removed, we need to refresh the domains cache if any domain was assigned to the content
|
||||
if (payload.Blueprint is false && payload.ChangeTypes.HasTypesAny(TreeChangeTypes.Remove))
|
||||
{
|
||||
idsRemoved.Add(payload.Id);
|
||||
}
|
||||
@@ -120,7 +120,11 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
// should rename it, and then, this is only for Deploy, and then, ???
|
||||
// if (Suspendable.PageCacheRefresher.CanUpdateDocumentCache)
|
||||
// ...
|
||||
NotifyPublishedSnapshotService(_publishedSnapshotService, AppCaches, payloads);
|
||||
if (payloads.Any(x => x.Blueprint is false))
|
||||
{
|
||||
// Only notify if the payload contains actual (non-blueprint) contents
|
||||
NotifyPublishedSnapshotService(_publishedSnapshotService, AppCaches, payloads);
|
||||
}
|
||||
|
||||
base.Refresh(payloads);
|
||||
}
|
||||
@@ -157,8 +161,13 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
}
|
||||
}
|
||||
|
||||
// TODO (V14): Change into a record
|
||||
public class JsonPayload
|
||||
{
|
||||
public JsonPayload()
|
||||
{ }
|
||||
|
||||
[Obsolete("Use the default constructor and property initializers.")]
|
||||
public JsonPayload(int id, Guid? key, TreeChangeTypes changeTypes)
|
||||
{
|
||||
Id = id;
|
||||
@@ -166,11 +175,13 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
ChangeTypes = changeTypes;
|
||||
}
|
||||
|
||||
public int Id { get; }
|
||||
public int Id { get; init; }
|
||||
|
||||
public Guid? Key { get; }
|
||||
public Guid? Key { get; init; }
|
||||
|
||||
public TreeChangeTypes ChangeTypes { get; }
|
||||
public TreeChangeTypes ChangeTypes { get; init; }
|
||||
|
||||
public bool Blueprint { get; init; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -134,8 +134,14 @@ public sealed class LanguageCacheRefresher : PayloadCacheRefresherBase<LanguageC
|
||||
ContentCacheRefresher.RefreshContentTypes(AppCaches); // we need to evict all IContent items
|
||||
|
||||
// now refresh all nucache
|
||||
ContentCacheRefresher.JsonPayload[] clearContentPayload =
|
||||
new[] { new ContentCacheRefresher.JsonPayload(0, null, TreeChangeTypes.RefreshAll) };
|
||||
ContentCacheRefresher.JsonPayload[] clearContentPayload = new[]
|
||||
{
|
||||
new ContentCacheRefresher.JsonPayload()
|
||||
{
|
||||
ChangeTypes = TreeChangeTypes.RefreshAll
|
||||
}
|
||||
};
|
||||
|
||||
ContentCacheRefresher.NotifyPublishedSnapshotService(_publishedSnapshotService, AppCaches, clearContentPayload);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using Umbraco.Cms.Core.Cache;
|
||||
@@ -132,7 +132,13 @@ public static class DistributedCacheExtensions
|
||||
|
||||
public static void RefreshAllContentCache(this DistributedCache dc)
|
||||
{
|
||||
ContentCacheRefresher.JsonPayload[] payloads = new[] { new ContentCacheRefresher.JsonPayload(0, null, TreeChangeTypes.RefreshAll) };
|
||||
ContentCacheRefresher.JsonPayload[] payloads = new[]
|
||||
{
|
||||
new ContentCacheRefresher.JsonPayload()
|
||||
{
|
||||
ChangeTypes = TreeChangeTypes.RefreshAll
|
||||
}
|
||||
};
|
||||
|
||||
// note: refresh all content cache does refresh content types too
|
||||
dc.RefreshByPayload(ContentCacheRefresher.UniqueId, payloads);
|
||||
@@ -145,8 +151,13 @@ public static class DistributedCacheExtensions
|
||||
return;
|
||||
}
|
||||
|
||||
IEnumerable<ContentCacheRefresher.JsonPayload> payloads = changes
|
||||
.Select(x => new ContentCacheRefresher.JsonPayload(x.Item.Id, x.Item.Key, x.ChangeTypes));
|
||||
IEnumerable<ContentCacheRefresher.JsonPayload> payloads = changes.Select(x => new ContentCacheRefresher.JsonPayload()
|
||||
{
|
||||
Id = x.Item.Id,
|
||||
Key = x.Item.Key,
|
||||
ChangeTypes = x.ChangeTypes,
|
||||
Blueprint = x.Item.Blueprint
|
||||
});
|
||||
|
||||
dc.RefreshByPayload(ContentCacheRefresher.UniqueId, payloads);
|
||||
}
|
||||
|
||||
@@ -51,13 +51,15 @@ public sealed class ContentIndexingNotificationHandler : INotificationHandler<Co
|
||||
|
||||
foreach (ContentCacheRefresher.JsonPayload payload in (ContentCacheRefresher.JsonPayload[])args.MessageObject)
|
||||
{
|
||||
if (payload.Blueprint)
|
||||
{
|
||||
// Skip blueprints
|
||||
continue;
|
||||
}
|
||||
|
||||
if (payload.ChangeTypes.HasType(TreeChangeTypes.Remove))
|
||||
{
|
||||
if (deleteBatch == null)
|
||||
{
|
||||
deleteBatch = new HashSet<int>();
|
||||
}
|
||||
|
||||
deleteBatch ??= new HashSet<int>();
|
||||
deleteBatch.Add(payload.Id);
|
||||
}
|
||||
else if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshAll))
|
||||
|
||||
@@ -210,7 +210,16 @@ internal class PublishedSnapshotService : IPublishedSnapshotService
|
||||
// they require.
|
||||
using (_contentStore.GetScopedWriteLock(_scopeProvider))
|
||||
{
|
||||
NotifyLocked(new[] { new ContentCacheRefresher.JsonPayload(0, null, TreeChangeTypes.RefreshAll) }, out _, out _);
|
||||
NotifyLocked(
|
||||
new[]
|
||||
{
|
||||
new ContentCacheRefresher.JsonPayload()
|
||||
{
|
||||
ChangeTypes = TreeChangeTypes.RefreshAll
|
||||
}
|
||||
},
|
||||
out _,
|
||||
out _);
|
||||
}
|
||||
|
||||
using (_mediaStore.GetScopedWriteLock(_scopeProvider))
|
||||
@@ -852,6 +861,12 @@ internal class PublishedSnapshotService : IPublishedSnapshotService
|
||||
// contentStore is write-locked during changes - see note above, calls to this method are wrapped in contentStore.GetScopedWriteLock
|
||||
foreach (ContentCacheRefresher.JsonPayload payload in payloads)
|
||||
{
|
||||
if (payload.Blueprint)
|
||||
{
|
||||
// Skip blueprints
|
||||
continue;
|
||||
}
|
||||
|
||||
_logger.LogDebug("Notified {ChangeTypes} for content {ContentId}", payload.ChangeTypes, payload.Id);
|
||||
|
||||
if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshAll))
|
||||
|
||||
Reference in New Issue
Block a user