Changes MediaCacheRefresher to be ICacheRefresher<T> and updates MacroCacheRefresher to use correct

macro object.
This commit is contained in:
Shannon Deminick
2013-03-12 03:11:35 +04:00
parent ec46d65bb4
commit 8d2e466e34
4 changed files with 32 additions and 32 deletions

View File

@@ -181,20 +181,7 @@ namespace Umbraco.Web.Cache
public static void RemoveMacroCache(this DistributedCache dc, int macroId)
{
dc.Remove(new Guid(DistributedCache.MacroCacheRefresherId), macroId);
}
/// <summary>
/// Removes the cache amongst servers for a macro item
/// </summary>
/// <param name="dc"></param>
/// <param name="macro"></param>
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);
}
}
}
/// <summary>
/// Removes the cache amongst servers for a macro item

View File

@@ -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
/// <summary>
/// Used to invalidate/refresh the cache for macros
/// </summary>
public class MacroCacheRefresher : ICacheRefresher<macro>
public class MacroCacheRefresher : ICacheRefresher<Macro>
{
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));

View File

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

View File

@@ -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;