Streamlines how macro cache is handled

This commit is contained in:
Shannon Deminick
2013-03-12 03:00:42 +04:00
parent 164f22aa50
commit ec46d65bb4
18 changed files with 167 additions and 141 deletions

View File

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