From ac2d010df39a1757cd772f131f1bcf4201f1cccb Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 23 Sep 2013 16:18:39 +0200 Subject: [PATCH] PublishedContent - refactor PublishedContentType cache --- .../PublishedContent/PublishedContentType.cs | 50 ++++++++++--------- .../Cache/ContentTypeCacheRefresher.cs | 9 +--- .../Cache/DataTypeCacheRefresher.cs | 4 +- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs index bfc1c456ca..773da45ccf 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs @@ -3,6 +3,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Web.Caching; +using System.Web.UI; using Umbraco.Core.Cache; namespace Umbraco.Core.Models.PublishedContent @@ -94,32 +95,35 @@ namespace Umbraco.Core.Models.PublishedContent #region Cache - // these methods are NOT called anymore - // instead, ContentTypeCacheRefresher and DataTypeCacheRefresher directly handle the ApplicationCache + // these methods are called by ContentTypeCacheRefresher and DataTypeCacheRefresher - //// internal, called by ContentTypeCacheRefresher - //internal static void ClearAll() - //{ - // Logging.LogHelper.Debug("Clear all."); - // ApplicationContext.Current.ApplicationCache.ClearStaticCacheByKeySearch("PublishedContentType_"); - //} + internal static void ClearAll() + { + Logging.LogHelper.Debug("Clear all."); + // ok and faster to do it by types, assuming noone else caches PublishedContentType instances + //ApplicationContext.Current.ApplicationCache.ClearStaticCacheByKeySearch("PublishedContentType_"); + ApplicationContext.Current.ApplicationCache.ClearStaticCacheObjectTypes(); + } - //// internal, called by ContentTypeCacheRefresher - //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 - // ApplicationContext.Current.ApplicationCache.ClearStaticCacheObjectTypes( - // (key, value) => value.Id == id); - //} + 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 + ApplicationContext.Current.ApplicationCache.ClearStaticCacheObjectTypes( + (key, value) => value.Id == id); + } - //// internal, called by DataTypeCacheRefresher - //internal static void ClearDataType(int id) - //{ - // Logging.LogHelper.Debug("Clear data type w/id {0}.", () => id); - // ApplicationContext.Current.ApplicationCache.ClearStaticCacheObjectTypes( - // (key, value) => value.PropertyTypes.Any(x => x.DataTypeId == id)); - //} + internal static void ClearDataType(int id) + { + Logging.LogHelper.Debug("Clear data type w/id {0}.", () => id); + // there is no recursion to handle here because a PublishedContentType contains *all* its + // properties ie both its own properties and those that were inherited (it's based upon an + // IContentTypeComposition) and so every PublishedContentType having a property based upon + // the cleared data type, be it local or inherited, will be cleared. + ApplicationContext.Current.ApplicationCache.ClearStaticCacheObjectTypes( + (key, value) => value.PropertyTypes.Any(x => x.DataTypeId == id)); + } public static PublishedContentType Get(PublishedItemType itemType, string alias) { diff --git a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs index 68d71032fd..983529fd01 100644 --- a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs @@ -131,10 +131,7 @@ namespace Umbraco.Web.Cache //clear static object cache global::umbraco.cms.businesslogic.ContentType.RemoveAllDataTypeCache(); - // see PublishedContentType for details - // can do by object types - noone else should cache published content type - //ApplicationContext.Current.ApplicationCache.ClearStaticCacheByKeySearch("PublishedContentType_"); - ApplicationContext.Current.ApplicationCache.ClearStaticCacheObjectTypes(); + PublishedContentType.ClearAll(); base.RefreshAll(); } @@ -256,9 +253,7 @@ namespace Umbraco.Web.Cache //clears the dictionary object cache of the legacy ContentType global::umbraco.cms.businesslogic.ContentType.RemoveFromDataTypeCache(payload.Alias); - // see PublishedContentType for details - ApplicationContext.Current.ApplicationCache.ClearStaticCacheObjectTypes( - (key, value) => value.Id == payload.Id); // faster than key strings comparisons + PublishedContentType.ClearContentType(payload.Id); //need to recursively clear the cache for each child content type foreach (var descendant in payload.DescendantPayloads) diff --git a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs index f17d3c3ebb..7691c1a125 100644 --- a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs @@ -123,9 +123,7 @@ namespace Umbraco.Web.Cache ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch( string.Format("{0}{1}", CacheKeys.DataTypeCacheKey, payload.UniqueId)); - // see PublishedContentType for details - ApplicationContext.Current.ApplicationCache.ClearStaticCacheObjectTypes( - (key, value) => value.PropertyTypes.Any(x => x.DataTypeId == payload.Id)); + PublishedContentType.ClearDataType(payload.Id); }); base.Refresh(jsonPayload);