Changed cache invalidation for macros to be done via events not inline in the editor.
This commit is contained in:
@@ -2,24 +2,32 @@
|
||||
using Umbraco.Core.Services;
|
||||
using umbraco;
|
||||
using umbraco.cms.businesslogic;
|
||||
using umbraco.cms.businesslogic.macro;
|
||||
using umbraco.cms.businesslogic.member;
|
||||
using System.Linq;
|
||||
|
||||
namespace Umbraco.Web.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// Special class made to listen to save events on objects where umbraco.library caches some of their objects
|
||||
/// Class which listens to events on business level objects in order to invalidate the cache amongst servers when data changes
|
||||
/// </summary>
|
||||
public class LibraryCacheRefresher : ApplicationEventHandler
|
||||
public class CacheRefresherEventHandler : ApplicationEventHandler
|
||||
{
|
||||
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
if (UmbracoSettings.UmbracoLibraryCacheDuration <= 0) return;
|
||||
|
||||
//Bind to macro events
|
||||
|
||||
Macro.AfterSave += MacroAfterSave;
|
||||
|
||||
//Bind to member events
|
||||
|
||||
Member.AfterSave += MemberAfterSave;
|
||||
Member.BeforeDelete += MemberBeforeDelete;
|
||||
|
||||
//Bind to media events
|
||||
|
||||
MediaService.Saved += MediaServiceSaved;
|
||||
//We need to perform all of the 'before' events here because we need a reference to the
|
||||
//media item's Path before it is moved/deleting/trashed
|
||||
@@ -29,6 +37,16 @@ namespace Umbraco.Web.Cache
|
||||
MediaService.Trashing += MediaServiceTrashing;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flush macro from cache
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
static void MacroAfterSave(Macro sender, SaveEventArgs e)
|
||||
{
|
||||
DistributedCache.Instance.RefreshMacroCache(sender.Id);
|
||||
}
|
||||
|
||||
static void MediaServiceTrashing(IMediaService sender, Core.Events.MoveEventArgs<Core.Models.IMedia> e)
|
||||
{
|
||||
ApplicationContext.Current.ApplicationCache.ClearLibraryCacheForMedia(e.Entity.Id);
|
||||
@@ -4,6 +4,9 @@ using umbraco.interfaces;
|
||||
|
||||
namespace Umbraco.Web.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to invalidate/refresh the cache for macros
|
||||
/// </summary>
|
||||
public class MacroCacheRefresher : ICacheRefresher
|
||||
{
|
||||
public string Name
|
||||
|
||||
@@ -247,7 +247,7 @@
|
||||
<Compile Include="Cache\CacheRefresherClient.cs" />
|
||||
<Compile Include="Cache\DistributedCache.cs" />
|
||||
<Compile Include="Cache\DistributedCacheExtensions.cs" />
|
||||
<Compile Include="Cache\LibraryCacheRefresher.cs" />
|
||||
<Compile Include="Cache\CacheRefresherEventHandler.cs" />
|
||||
<Compile Include="Cache\MacroCacheRefresher.cs" />
|
||||
<Compile Include="Cache\MediaLibraryRefreshers.cs" />
|
||||
<Compile Include="Cache\MemberLibraryRefreshers.cs" />
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace umbraco
|
||||
{
|
||||
|
||||
[Obsolete("This class is no longer used, use Umbraco.Web.Cache.LibraryCacheRefresher instead")]
|
||||
public class LibraryCacheRefresher : Umbraco.Web.Cache.LibraryCacheRefresher
|
||||
public class LibraryCacheRefresher : Umbraco.Web.Cache.CacheRefresherEventHandler
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -109,10 +109,6 @@ namespace umbraco.cms.presentation.developer
|
||||
|
||||
}
|
||||
|
||||
// Flush macro from cache!
|
||||
DistributedCache.Instance.RefreshMacroCache(macroID);
|
||||
|
||||
|
||||
ClientTools.ShowSpeechBubble(speechBubbleIcon.save, "Macro saved", "");
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user