From adf3e2dfe0e40f7c800e58422473ba863a88f655 Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 10 Mar 2016 13:59:50 +0100 Subject: [PATCH] U4-5797 - fix PublishedContentType cache refresh for compositions --- .../PublishedContent/PublishedContentType.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs index 676c3366ac..d05960b08f 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs @@ -114,10 +114,25 @@ namespace Umbraco.Core.Models.PublishedContent internal static void ClearContentType(int id) { Logging.LogHelper.Debug("Clear content type w/id {0}.", () => id); - // requires a predicate because the key does not contain the ID - // faster than key strings comparisons anyway + + // we don't support "get all" at the moment - so, cheating + var all = ApplicationContext.Current.ApplicationCache.StaticCache.GetCacheItemsByKeySearch("PublishedContentType_").ToArray(); + + // the one we want to clear + var clr = all.FirstOrDefault(x => x.Id == id); + if (clr == null) return; + + // those that have that one in their composition aliases + // note: CompositionAliases contains all recursive aliases + var oth = all.Where(x => x.CompositionAliases.InvariantContains(clr.Alias)).Select(x => x.Id); + + // merge ids + var ids = oth.Concat(new[] { clr.Id }).ToArray(); + + // clear them all at once + // we don't support "clear many at once" at the moment - so, cheating ApplicationContext.Current.ApplicationCache.StaticCache.ClearCacheObjectTypes( - (key, value) => value.Id == id); + (key, value) => ids.Contains(value.Id)); } internal static void ClearDataType(int id)