Files
Umbraco-CMS/src/Umbraco.Web/Cache/MacroCacheRefresher.cs

73 lines
1.7 KiB
C#
Raw Normal View History

using System;
2013-03-12 03:00:42 +04:00
using Umbraco.Core;
using Umbraco.Core.Cache;
using umbraco;
using umbraco.interfaces;
namespace Umbraco.Web.Cache
{
/// <summary>
/// Used to invalidate/refresh the cache for macros
/// </summary>
2013-03-12 03:00:42 +04:00
public class MacroCacheRefresher : ICacheRefresher<macro>
{
2013-03-12 03:00:42 +04:00
internal static string[] GetCacheKeys(string alias)
{
return new[] { CacheKeys.MacroRuntimeCacheKey + alias, CacheKeys.UmbracoMacroCacheKey + alias };
}
public string Name
{
get
{
return "Macro cache refresher";
}
}
public Guid UniqueIdentifier
{
get
{
return new Guid(DistributedCache.MacroCacheRefresherId);
}
}
public void RefreshAll()
{
}
public void Refresh(Guid id)
{
}
void ICacheRefresher.Refresh(int id)
{
2013-03-12 03:00:42 +04:00
if (id <= 0) return;
var m = new macro(id);
Remove(m);
}
void ICacheRefresher.Remove(int id)
{
2013-03-12 03:00:42 +04:00
if (id <= 0) return;
var m = new macro(id);
Remove(m);
}
public void Refresh(macro instance)
{
Remove(instance);
}
2013-03-12 03:00:42 +04:00
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));
}
}
}
}