2013-02-06 09:53:13 +06:00
|
|
|
|
using System;
|
2013-03-12 03:00:42 +04:00
|
|
|
|
using Umbraco.Core.Cache;
|
2013-07-23 11:46:18 +10:00
|
|
|
|
using Umbraco.Core.Models;
|
2017-09-08 19:39:13 +02:00
|
|
|
|
using Umbraco.Core.Services;
|
2015-01-13 13:33:39 +11:00
|
|
|
|
|
2013-02-06 09:53:13 +06:00
|
|
|
|
namespace Umbraco.Web.Cache
|
|
|
|
|
|
{
|
2016-05-26 17:12:04 +02:00
|
|
|
|
public sealed class TemplateCacheRefresher : CacheRefresherBase<TemplateCacheRefresher>
|
2013-02-06 09:53:13 +06:00
|
|
|
|
{
|
2017-09-19 15:51:47 +02:00
|
|
|
|
private readonly IdkMap _idkMap;
|
2017-09-08 19:39:13 +02:00
|
|
|
|
|
|
|
|
|
|
public TemplateCacheRefresher(CacheHelper cacheHelper, IdkMap idkMap)
|
2016-05-26 17:12:04 +02:00
|
|
|
|
: base(cacheHelper)
|
2017-09-08 19:39:13 +02:00
|
|
|
|
{
|
|
|
|
|
|
_idkMap = idkMap;
|
|
|
|
|
|
}
|
2016-05-18 18:44:08 +02:00
|
|
|
|
|
2016-05-26 17:12:04 +02:00
|
|
|
|
#region Define
|
2013-03-21 22:53:58 +06:00
|
|
|
|
|
2017-07-11 19:21:13 +02:00
|
|
|
|
protected override TemplateCacheRefresher This => this;
|
2013-02-06 09:53:13 +06:00
|
|
|
|
|
2016-05-26 17:12:04 +02:00
|
|
|
|
public static readonly Guid UniqueId = Guid.Parse("DD12B6A0-14B9-46e8-8800-C154F74047C8");
|
|
|
|
|
|
|
|
|
|
|
|
public override Guid RefresherUniqueId => UniqueId;
|
|
|
|
|
|
|
|
|
|
|
|
public override string Name => "Template Cache Refresher";
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Refresher
|
2013-02-06 09:53:13 +06:00
|
|
|
|
|
2013-03-21 22:53:58 +06:00
|
|
|
|
public override void Refresh(int id)
|
2013-02-06 09:53:13 +06:00
|
|
|
|
{
|
2013-02-07 05:26:53 +06:00
|
|
|
|
RemoveFromCache(id);
|
2013-03-21 22:53:58 +06:00
|
|
|
|
base.Refresh(id);
|
2013-02-06 09:53:13 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-21 22:53:58 +06:00
|
|
|
|
public override void Remove(int id)
|
2013-02-06 09:53:13 +06:00
|
|
|
|
{
|
2013-02-07 05:26:53 +06:00
|
|
|
|
RemoveFromCache(id);
|
2015-08-05 16:30:21 +02:00
|
|
|
|
|
|
|
|
|
|
//During removal we need to clear the runtime cache for templates, content and content type instances!!!
|
|
|
|
|
|
// all three of these types are referenced by templates, and the cache needs to be cleared on every server,
|
|
|
|
|
|
// otherwise things like looking up content type's after a template is removed is still going to show that
|
|
|
|
|
|
// it has an associated template.
|
2016-01-07 19:27:59 +01:00
|
|
|
|
ClearAllIsolatedCacheByEntityType<IContent>();
|
|
|
|
|
|
ClearAllIsolatedCacheByEntityType<IContentType>();
|
2015-08-05 16:30:21 +02:00
|
|
|
|
|
2013-03-21 22:53:58 +06:00
|
|
|
|
base.Remove(id);
|
2013-02-07 05:26:53 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void RemoveFromCache(int id)
|
|
|
|
|
|
{
|
2017-09-08 19:39:13 +02:00
|
|
|
|
_idkMap.ClearCache(id);
|
2016-05-26 17:12:04 +02:00
|
|
|
|
CacheHelper.RuntimeCache.ClearCacheItem($"{CacheKeys.TemplateFrontEndCacheKey}{id}");
|
2013-03-22 02:08:55 +06:00
|
|
|
|
|
2015-08-05 16:30:21 +02:00
|
|
|
|
//need to clear the runtime cache for templates
|
2016-01-07 19:27:59 +01:00
|
|
|
|
ClearAllIsolatedCacheByEntityType<ITemplate>();
|
2013-02-06 09:53:13 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-26 17:12:04 +02:00
|
|
|
|
#endregion
|
2013-02-06 09:53:13 +06:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|