Updated ContentTypeCacheRefresher to ensure that content xml cache is only refreshed for doc types not

media types, also ensures that the route cache is cleared (#U4-1969). Changes the deletion of media and
doc types to use the new Api - this ensures that cache is refreshed properly.
This commit is contained in:
Shannon Deminick
2013-03-21 01:04:27 +06:00
parent 266aa3423b
commit c5a0da6aa5
4 changed files with 62 additions and 13 deletions

View File

@@ -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;
}
/// <summary>
/// Fires when a media type is deleted
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static void ContentTypeServiceDeletedMediaType(IContentTypeService sender, Core.Events.DeleteEventArgs<IMediaType> e)
{
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveMediaTypeCache(x));
}
/// <summary>
/// Fires when a content type is deleted
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static void ContentTypeServiceDeletedContentType(IContentTypeService sender, Core.Events.DeleteEventArgs<IContentType> e)
{
e.DeletedEntities.ForEach(contentType => DistributedCache.Instance.RemoveContentTypeCache(contentType));
}
/// <summary>
/// Fires when a media type is saved
/// </summary>

View File

@@ -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();
}
}
}
}