diff --git a/src/Umbraco.Core/PublishedContentHelper.cs b/src/Umbraco.Core/PublishedContentHelper.cs index 765b012164..1e7fc1ef18 100644 --- a/src/Umbraco.Core/PublishedContentHelper.cs +++ b/src/Umbraco.Core/PublishedContentHelper.cs @@ -22,37 +22,14 @@ namespace Umbraco.Core /// internal class PublishedContentHelper : ApplicationEventHandler { - - #region event handlers to ensure that the cache is cleared when content types change - protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) - { - ContentTypeService.SavedContentType += ContentTypeServiceSavedContentType; - ContentTypeService.SavedMediaType += ContentTypeServiceSavedMediaType; - ContentTypeService.DeletedContentType += ContentTypeServiceDeletedContentType; - ContentTypeService.DeletedMediaType += ContentTypeServiceDeletedMediaType; - } - - static void ContentTypeServiceDeletedMediaType(IContentTypeService sender, Events.DeleteEventArgs e) + /// + /// Used to invalidate the cache from the ICacherefresher + /// + internal static void ClearPropertyTypeCache() { PropertyTypeCache.Clear(); } - static void ContentTypeServiceDeletedContentType(IContentTypeService sender, Events.DeleteEventArgs e) - { - PropertyTypeCache.Clear(); - } - - static void ContentTypeServiceSavedMediaType(IContentTypeService sender, Events.SaveEventArgs e) - { - PropertyTypeCache.Clear(); - } - - static void ContentTypeServiceSavedContentType(IContentTypeService sender, Events.SaveEventArgs e) - { - PropertyTypeCache.Clear(); - } - #endregion - /// /// This callback is used only for unit tests which enables us to return any data we want and not rely on having the data in a database /// @@ -77,11 +54,16 @@ namespace Umbraco.Core { var result = applicationContext.Services.ContentTypeService.GetContentType(docTypeAlias); if (result == null) return Guid.Empty; - if (!result.PropertyTypes.Any(x => x.Alias.InvariantEquals(propertyAlias))) + + //SD: we need to check for 'any' here because the collection is backed by KeyValuePair which is a struct + // and can never be null so FirstOrDefault doesn't actually work. Have told Seb and Morten about thsi + // issue. + if (!result.CompositionPropertyTypes.Any(x => x.Alias.InvariantEquals(propertyAlias))) { return Guid.Empty; } - var property = result.PropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyAlias)); + var property = result.CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyAlias)); + //as per above, this will never be null but we'll keep the check here anyways. if (property == null) return Guid.Empty; return property.DataTypeId; }); diff --git a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs index 46e8b91371..c724bc4c22 100644 --- a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs @@ -129,6 +129,7 @@ namespace Umbraco.Web.Cache ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(CacheKeys.ContentTypeCacheKey); //clear static object cache global::umbraco.cms.businesslogic.ContentType.RemoveAllDataTypeCache(); + PublishedContentHelper.ClearPropertyTypeCache(); base.RefreshAll(); } @@ -247,6 +248,7 @@ namespace Umbraco.Web.Cache //clears the dictionary object cache of the legacy ContentType global::umbraco.cms.businesslogic.ContentType.RemoveFromDataTypeCache(payload.Alias); + PublishedContentHelper.ClearPropertyTypeCache(); //need to recursively clear the cache for each child content type foreach (var descendant in payload.DescendantPayloads)