Explicitly flush isolated caches by key for content updates (#20519)

* Explicitly flush isolated caches by key for content updates

* Apply suggestions from code review

---------

Co-authored-by: Andy Butland <abutland73@gmail.com>
This commit is contained in:
Kenn Jacobsen
2025-10-16 12:56:32 +02:00
committed by GitHub
parent 3830d75413
commit 498754e170
4 changed files with 304 additions and 0 deletions

View File

@@ -1378,6 +1378,11 @@ public class DocumentRepository : ContentRepositoryBase<int, IContent, DocumentR
entity.ResetDirtyProperties();
// We need to flush the isolated cache by key explicitly here.
// The ContentCacheRefresher does the same thing, but by the time it's invoked, custom notification handlers
// might have already consumed the cached version (which at this point is the previous version).
IsolatedCache.ClearByKey(RepositoryCacheKeys.GetKey<IContent, Guid>(entity.Key));
// troubleshooting
//if (Database.ExecuteScalar<int>($"SELECT COUNT(*) FROM {Constants.DatabaseSchema.Tables.DocumentVersion} JOIN {Constants.DatabaseSchema.Tables.ContentVersion} ON {Constants.DatabaseSchema.Tables.DocumentVersion}.id={Constants.DatabaseSchema.Tables.ContentVersion}.id WHERE published=1 AND nodeId=" + content.Id) > 1)
//{

View File

@@ -541,6 +541,11 @@ public class MediaRepository : ContentRepositoryBase<int, IMedia, MediaRepositor
OnUowRefreshedEntity(new MediaRefreshNotification(entity, new EventMessages()));
entity.ResetDirtyProperties();
// We need to flush the isolated cache by key explicitly here.
// The MediaCacheRefresher does the same thing, but by the time it's invoked, custom notification handlers
// might have already consumed the cached version (which at this point is the previous version).
IsolatedCache.ClearByKey(RepositoryCacheKeys.GetKey<IMedia, Guid>(entity.Key));
}
protected override void PersistDeletedItem(IMedia entity)