Files
Umbraco-CMS/src/Umbraco.Core/Cache/TemplateCacheRefresher.cs

67 lines
2.2 KiB
C#
Raw Normal View History

2018-06-29 19:52:40 +02:00
using System;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.Services;
2018-06-29 19:52:40 +02:00
namespace Umbraco.Cms.Core.Cache
2018-06-29 19:52:40 +02:00
{
public sealed class TemplateCacheRefresher : CacheRefresherBase<TemplateCacheRefresher>
{
private readonly IIdKeyMap _idKeyMap;
private readonly IContentTypeCommonRepository _contentTypeCommonRepository;
2018-06-29 19:52:40 +02:00
public TemplateCacheRefresher(AppCaches appCaches, IIdKeyMap idKeyMap, IContentTypeCommonRepository contentTypeCommonRepository)
2019-01-17 08:34:29 +01:00
: base(appCaches)
2018-06-29 19:52:40 +02:00
{
_idKeyMap = idKeyMap;
_contentTypeCommonRepository = contentTypeCommonRepository;
2018-06-29 19:52:40 +02:00
}
#region Define
protected override TemplateCacheRefresher This => this;
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
public override void Refresh(int id)
{
RemoveFromCache(id);
base.Refresh(id);
}
public override void Remove(int id)
{
RemoveFromCache(id);
//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.
ClearAllIsolatedCacheByEntityType<IContent>();
ClearAllIsolatedCacheByEntityType<IContentType>();
_contentTypeCommonRepository.ClearCache();
2018-06-29 19:52:40 +02:00
base.Remove(id);
}
private void RemoveFromCache(int id)
{
_idKeyMap.ClearCache(id);
2019-01-17 11:01:23 +01:00
AppCaches.RuntimeCache.Clear($"{CacheKeys.TemplateFrontEndCacheKey}{id}");
2018-06-29 19:52:40 +02:00
//need to clear the runtime cache for templates
ClearAllIsolatedCacheByEntityType<ITemplate>();
}
#endregion
}
}