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;
|
2013-03-12 22:58:21 +04:00
|
|
|
|
using System.Linq;
|
2013-02-06 09:53:13 +06:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Cache
|
|
|
|
|
|
{
|
2013-02-07 04:45:05 +06:00
|
|
|
|
/// <summary>
|
2013-03-18 21:18:22 +06:00
|
|
|
|
/// A cache refresher to ensure macro cache is updated when members change
|
2013-02-07 04:45:05 +06:00
|
|
|
|
/// </summary>
|
2013-03-18 21:18:22 +06:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// This is not intended to be used directly in your code and it should be sealed but due to legacy code we cannot seal it.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public class MacroCacheRefresher : ICacheRefresher<Macro>, ICacheRefresher<macro>
|
2013-02-06 09:53:13 +06:00
|
|
|
|
{
|
2013-03-12 22:58:21 +04:00
|
|
|
|
internal static string[] GetAllMacroCacheKeys()
|
2013-03-12 03:00:42 +04:00
|
|
|
|
{
|
2013-03-12 22:58:21 +04:00
|
|
|
|
return new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
CacheKeys.MacroCacheKey,
|
|
|
|
|
|
CacheKeys.MacroControlCacheKey,
|
|
|
|
|
|
CacheKeys.MacroHtmlCacheKey,
|
|
|
|
|
|
CacheKeys.MacroHtmlDateAddedCacheKey,
|
|
|
|
|
|
CacheKeys.MacroControlDateAddedCacheKey
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal static string[] GetCacheKeysForAlias(string alias)
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetAllMacroCacheKeys().Select(x => x + alias).ToArray();
|
2013-03-12 03:00:42 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
{
|
2013-03-12 22:58:21 +04:00
|
|
|
|
ApplicationContext.Current.ApplicationCache.ClearCacheObjectTypes<MacroCacheContent>();
|
|
|
|
|
|
GetAllMacroCacheKeys().ForEach(
|
|
|
|
|
|
prefix =>
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(prefix));
|
2013-02-06 09:53:13 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Refresh(Guid id)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-12 17:08:31 +04:00
|
|
|
|
public void Refresh(int id)
|
2013-02-06 09:53:13 +06:00
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-12 17:08:31 +04:00
|
|
|
|
public void Remove(int id)
|
2013-02-06 09:53:13 +06:00
|
|
|
|
{
|
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 22:58:21 +04:00
|
|
|
|
GetCacheKeysForAlias(instance.Alias).ForEach(
|
2013-03-12 03:00:42 +04:00
|
|
|
|
alias =>
|
2013-03-12 22:58:21 +04:00
|
|
|
|
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(alias));
|
2013-03-12 03:00:42 +04:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2013-03-12 17:08:31 +04:00
|
|
|
|
|
|
|
|
|
|
public void Refresh(macro instance)
|
|
|
|
|
|
{
|
|
|
|
|
|
Remove(instance);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Remove(macro instance)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (instance == null || instance.Model == null) return;
|
|
|
|
|
|
var m = instance.Model;
|
2013-03-12 22:58:21 +04:00
|
|
|
|
GetCacheKeysForAlias(m.Alias).ForEach(
|
2013-03-12 17:08:31 +04:00
|
|
|
|
alias =>
|
2013-03-12 22:58:21 +04:00
|
|
|
|
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(alias));
|
2013-03-12 17:08:31 +04:00
|
|
|
|
}
|
2013-02-06 09:53:13 +06:00
|
|
|
|
}
|
|
|
|
|
|
}
|