diff --git a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs index fcbc17600c..73fe852abe 100644 --- a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs +++ b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs @@ -36,6 +36,8 @@ namespace Umbraco.Web.Cache ContentTypeService.SavedContentType += ContentTypeServiceSavedContentType; ContentTypeService.SavedMediaType += ContentTypeServiceSavedMediaType; + ContentTypeService.DeletedContentType += ContentTypeServiceDeletedContentType; + ContentTypeService.DeletedMediaType += ContentTypeServiceDeletedMediaType; //Bind to user events @@ -68,6 +70,26 @@ namespace Umbraco.Web.Cache MediaService.Trashing += MediaServiceTrashing; } + /// + /// Fires when a media type is deleted + /// + /// + /// + static void ContentTypeServiceDeletedMediaType(IContentTypeService sender, Core.Events.DeleteEventArgs e) + { + e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveMediaTypeCache(x)); + } + + /// + /// Fires when a content type is deleted + /// + /// + /// + static void ContentTypeServiceDeletedContentType(IContentTypeService sender, Core.Events.DeleteEventArgs e) + { + e.DeletedEntities.ForEach(contentType => DistributedCache.Instance.RemoveContentTypeCache(contentType)); + } + /// /// Fires when a media type is saved /// diff --git a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs index 2a37efed59..4f8aed80d8 100644 --- a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs @@ -8,6 +8,8 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.EntityBase; using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence.Caching; +using Umbraco.Web.PublishedCache; +using Umbraco.Web.PublishedCache.LegacyXmlCache; namespace Umbraco.Web.Cache { @@ -87,7 +89,8 @@ namespace Umbraco.Web.Cache /// - ContentType.RemoveFromDataTypeCache (clears static object/dictionary cache) /// - InMemoryCacheProvider.Current.Clear(); /// - RuntimeCacheProvider.Current.Clear(); - /// + /// - RoutesCache.Clear(); + /// /// TODO: Needs to update any content items that this effects for the xml cache... /// it is only handled in the ContentTypeControlNew.ascx, not by business logic/events. - The xml cache needs to be updated /// when the doc type alias changes or when a property type is removed, the ContentService.RePublishAll should be executed anytime either of these happens. @@ -101,12 +104,17 @@ namespace Umbraco.Web.Cache //clear the cache for each item ClearContentTypeCache(contentType); - //here we need to check if the alias of the content type changed or if one of the properties was removed. - var dirty = contentType as IRememberBeingDirty; - if (dirty == null) return; - if (dirty.WasPropertyDirty("Alias") || dirty.WasPropertyDirty("HasPropertyTypeBeenRemoved")) + //we only need to do this for IContentType NOT for IMediaType, we don't want to refresh the whole cache + //if a media type has changed. + if (contentType is IContentType) { - needsContentRefresh = true; + //here we need to check if the alias of the content type changed or if one of the properties was removed. + var dirty = contentType as IRememberBeingDirty; + if (dirty == null) return; + if (dirty.WasPropertyDirty("Alias") || dirty.WasPropertyDirty("HasPropertyTypeBeenRemoved")) + { + needsContentRefresh = true; + } } }); @@ -121,7 +129,20 @@ namespace Umbraco.Web.Cache if (contentTypes.Any()) { InMemoryCacheProvider.Current.Clear(); - RuntimeCacheProvider.Current.Clear(); + RuntimeCacheProvider.Current.Clear(); + + //we only need to do this for IContentType NOT for IMediaType, we don't want to refresh the whole routes + //cache if only a media type has changed. + if (contentTypes.Any(x => x is IContentType)) + { + //we need to clear the routes cache here! + //TODO: Is there a better way to handle this without casting ? + var contentCache = PublishedContentCacheResolver.Current.ContentCache as PublishedContentCache; + if (contentCache != null) + { + contentCache.RoutesCache.Clear(); + } + } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/MediaTypeTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/MediaTypeTasks.cs index df96c8a249..45955828ca 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/MediaTypeTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/MediaTypeTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Core; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -57,7 +58,11 @@ namespace umbraco public bool Delete() { - new cms.businesslogic.media.MediaType(_parentID).delete(); + var mediaType = ApplicationContext.Current.Services.ContentTypeService.GetMediaType(ParentID); + if (mediaType != null) + { + ApplicationContext.Current.Services.ContentTypeService.Delete(mediaType); + } return false; } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs index 569930ad06..16658ff59a 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/nodetypeTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Core; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -68,11 +69,11 @@ namespace umbraco public bool Delete() { - new cms.businesslogic.web.DocumentType(ParentID).delete(); - - //after a document type is deleted, we clear the cache, as some content will now have disappeared. - library.RefreshContent(); - + var docType = ApplicationContext.Current.Services.ContentTypeService.GetContentType(ParentID); + if (docType != null) + { + ApplicationContext.Current.Services.ContentTypeService.Delete(docType); + } return false; }