2013-02-06 09:53:13 +06:00
|
|
|
|
using System;
|
2013-03-12 03:00:42 +04:00
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Cache;
|
2013-02-06 09:53:13 +06:00
|
|
|
|
using umbraco;
|
2013-03-12 03:11:35 +04:00
|
|
|
|
using umbraco.cms.businesslogic.macro;
|
2013-02-06 09:53:13 +06:00
|
|
|
|
using umbraco.interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Cache
|
|
|
|
|
|
{
|
2013-02-07 04:45:05 +06:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Used to invalidate/refresh the cache for macros
|
|
|
|
|
|
/// </summary>
|
2013-03-12 03:11:35 +04:00
|
|
|
|
public class MacroCacheRefresher : ICacheRefresher<Macro>
|
2013-02-06 09:53:13 +06:00
|
|
|
|
{
|
2013-03-12 03:00:42 +04:00
|
|
|
|
internal static string[] GetCacheKeys(string alias)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new[] { CacheKeys.MacroRuntimeCacheKey + alias, CacheKeys.UmbracoMacroCacheKey + alias };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-02-06 09:53:13 +06:00
|
|
|
|
public string Name
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return "Macro cache refresher";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Guid UniqueIdentifier
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2013-02-07 04:04:51 +06:00
|
|
|
|
return new Guid(DistributedCache.MacroCacheRefresherId);
|
2013-02-06 09:53:13 +06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2013-03-12 03:11:35 +04:00
|
|
|
|
var m = new Macro(id);
|
2013-03-12 03:00:42 +04:00
|
|
|
|
Remove(m);
|
2013-02-06 09:53:13 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ICacheRefresher.Remove(int id)
|
|
|
|
|
|
{
|
2013-03-12 03:00:42 +04:00
|
|
|
|
if (id <= 0) return;
|
2013-03-12 03:11:35 +04:00
|
|
|
|
var m = new Macro(id);
|
2013-03-12 03:00:42 +04:00
|
|
|
|
Remove(m);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-12 03:11:35 +04:00
|
|
|
|
public void Refresh(Macro instance)
|
2013-03-12 03:00:42 +04:00
|
|
|
|
{
|
|
|
|
|
|
Remove(instance);
|
2013-02-06 09:53:13 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-12 03:11:35 +04:00
|
|
|
|
public void Remove(Macro instance)
|
2013-03-12 03:00:42 +04:00
|
|
|
|
{
|
2013-03-12 03:11:35 +04:00
|
|
|
|
if (instance != null && instance.Id > 0)
|
2013-03-12 03:00:42 +04:00
|
|
|
|
{
|
2013-03-12 03:11:35 +04:00
|
|
|
|
GetCacheKeys(instance.Alias).ForEach(
|
2013-03-12 03:00:42 +04:00
|
|
|
|
alias =>
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.ClearCacheItem(alias));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2013-02-06 09:53:13 +06:00
|
|
|
|
}
|
|
|
|
|
|
}
|