Streamlines how macro cache is handled
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using umbraco;
|
||||
using umbraco.interfaces;
|
||||
|
||||
@@ -7,8 +9,13 @@ namespace Umbraco.Web.Cache
|
||||
/// <summary>
|
||||
/// Used to invalidate/refresh the cache for macros
|
||||
/// </summary>
|
||||
public class MacroCacheRefresher : ICacheRefresher
|
||||
public class MacroCacheRefresher : ICacheRefresher<macro>
|
||||
{
|
||||
internal static string[] GetCacheKeys(string alias)
|
||||
{
|
||||
return new[] { CacheKeys.MacroRuntimeCacheKey + alias, CacheKeys.UmbracoMacroCacheKey + alias };
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
@@ -35,13 +42,32 @@ namespace Umbraco.Web.Cache
|
||||
|
||||
void ICacheRefresher.Refresh(int id)
|
||||
{
|
||||
macro.GetMacro(id).removeFromCache();
|
||||
if (id <= 0) return;
|
||||
var m = new macro(id);
|
||||
Remove(m);
|
||||
}
|
||||
|
||||
void ICacheRefresher.Remove(int id)
|
||||
{
|
||||
macro.GetMacro(id).removeFromCache();
|
||||
if (id <= 0) return;
|
||||
var m = new macro(id);
|
||||
Remove(m);
|
||||
}
|
||||
|
||||
public void Refresh(macro instance)
|
||||
{
|
||||
Remove(instance);
|
||||
}
|
||||
|
||||
public void Remove(macro instance)
|
||||
{
|
||||
if (instance != null && instance.Model != null && instance.Model.Id > 0)
|
||||
{
|
||||
GetCacheKeys(instance.Model.Alias).ForEach(
|
||||
alias =>
|
||||
ApplicationContext.Current.ApplicationCache.ClearCacheItem(alias));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user