diff --git a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs
index b25e53f142..a258cc0a59 100644
--- a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs
+++ b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs
@@ -181,20 +181,7 @@ namespace Umbraco.Web.Cache
public static void RemoveMacroCache(this DistributedCache dc, int macroId)
{
dc.Remove(new Guid(DistributedCache.MacroCacheRefresherId), macroId);
- }
-
- ///
- /// Removes the cache amongst servers for a macro item
- ///
- ///
- ///
- public static void RemoveMacroCache(this DistributedCache dc, macro macro)
- {
- if (macro != null && macro.Model != null)
- {
- dc.Remove(new Guid(DistributedCache.MacroCacheRefresherId), macro1 => macro1.Model.Id, macro);
- }
- }
+ }
///
/// Removes the cache amongst servers for a macro item
diff --git a/src/Umbraco.Web/Cache/MacroCacheRefresher.cs b/src/Umbraco.Web/Cache/MacroCacheRefresher.cs
index d5136414d5..0496a04d31 100644
--- a/src/Umbraco.Web/Cache/MacroCacheRefresher.cs
+++ b/src/Umbraco.Web/Cache/MacroCacheRefresher.cs
@@ -2,6 +2,7 @@
using Umbraco.Core;
using Umbraco.Core.Cache;
using umbraco;
+using umbraco.cms.businesslogic.macro;
using umbraco.interfaces;
namespace Umbraco.Web.Cache
@@ -9,7 +10,7 @@ namespace Umbraco.Web.Cache
///
/// Used to invalidate/refresh the cache for macros
///
- public class MacroCacheRefresher : ICacheRefresher
+ public class MacroCacheRefresher : ICacheRefresher
{
internal static string[] GetCacheKeys(string alias)
{
@@ -43,27 +44,27 @@ namespace Umbraco.Web.Cache
void ICacheRefresher.Refresh(int id)
{
if (id <= 0) return;
- var m = new macro(id);
+ var m = new Macro(id);
Remove(m);
}
void ICacheRefresher.Remove(int id)
{
if (id <= 0) return;
- var m = new macro(id);
+ var m = new Macro(id);
Remove(m);
}
- public void Refresh(macro instance)
+ public void Refresh(Macro instance)
{
Remove(instance);
}
- public void Remove(macro instance)
+ public void Remove(Macro instance)
{
- if (instance != null && instance.Model != null && instance.Model.Id > 0)
+ if (instance != null && instance.Id > 0)
{
- GetCacheKeys(instance.Model.Alias).ForEach(
+ GetCacheKeys(instance.Alias).ForEach(
alias =>
ApplicationContext.Current.ApplicationCache.ClearCacheItem(alias));
diff --git a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs
index 74d3e91837..4455c0d9c5 100644
--- a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs
+++ b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs
@@ -1,11 +1,12 @@
using System;
using Umbraco.Core;
using Umbraco.Core.Cache;
+using Umbraco.Core.Models;
using umbraco.interfaces;
namespace Umbraco.Web.Cache
{
- public class MediaCacheRefresher : ICacheRefresher
+ public class MediaCacheRefresher : ICacheRefresher
{
public Guid UniqueIdentifier
{
@@ -23,35 +24,43 @@ namespace Umbraco.Web.Cache
public void Refresh(int id)
{
- ClearCache(id);
+ ClearCache(ApplicationContext.Current.Services.MediaService.GetById(id));
}
public void Remove(int id)
{
- ClearCache(id);
+ ClearCache(ApplicationContext.Current.Services.MediaService.GetById(id));
}
public void Refresh(Guid id)
{
}
- private static void ClearCache(int id)
+ public void Refresh(IMedia instance)
{
- var m = ApplicationContext.Current.Services.MediaService.GetById(id);
- if (m == null) return;
+ ClearCache(instance);
+ }
- foreach (var idPart in m.Path.Split(','))
+ public void Remove(IMedia instance)
+ {
+ ClearCache(instance);
+ }
+
+ private static void ClearCache(IMedia media)
+ {
+ if (media == null) return;
+
+ foreach (var idPart in media.Path.Split(','))
{
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(
string.Format("UL_{0}_{1}_True", CacheKeys.GetMediaCacheKey, idPart));
// Also clear calls that only query this specific item!
- if (idPart == m.Id.ToString())
+ if (idPart == media.Id.ToString())
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(
- string.Format("UL_{0}_{1}", CacheKeys.GetMediaCacheKey, id));
+ string.Format("UL_{0}_{1}", CacheKeys.GetMediaCacheKey, media.Id));
}
}
-
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/umbraco.presentation/macro.cs b/src/Umbraco.Web/umbraco.presentation/macro.cs
index 503a18f30a..1410ccbc8e 100644
--- a/src/Umbraco.Web/umbraco.presentation/macro.cs
+++ b/src/Umbraco.Web/umbraco.presentation/macro.cs
@@ -199,7 +199,10 @@ namespace umbraco
[Obsolete("Use DistributedCache.Instance.RemoveMacroCache instead, macro cache will automatically be cleared and shouldn't need to be manually cleared.")]
public bool removeFromCache()
{
- DistributedCache.Instance.RemoveMacroCache(this);
+ if (this.Model != null)
+ {
+ DistributedCache.Instance.RemoveMacroCache(this.Model.Id);
+ }
//this always returned false... hrm. oh well i guess we leave it like that
return false;