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

74 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.cms.businesslogic.macro;
using umbraco.interfaces;
namespace Umbraco.Web.Cache
{
/// <summary>
/// Used to invalidate/refresh the cache for macros
/// </summary>
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);
2013-03-12 03:00:42 +04:00
Remove(m);
}
void ICacheRefresher.Remove(int id)
{
2013-03-12 03:00:42 +04:00
if (id <= 0) return;
var m = new Macro(id);
2013-03-12 03:00:42 +04:00
Remove(m);
}
public void Refresh(Macro instance)
2013-03-12 03:00:42 +04:00
{
Remove(instance);
}
public void Remove(Macro instance)
2013-03-12 03:00:42 +04:00
{
if (instance != null && instance.Id > 0)
2013-03-12 03:00:42 +04:00
{
GetCacheKeys(instance.Alias).ForEach(
2013-03-12 03:00:42 +04:00
alias =>
ApplicationContext.Current.ApplicationCache.ClearCacheItem(alias));
}
}
}
}