2018-06-29 19:52:40 +02:00
|
|
|
|
using System;
|
2021-02-18 11:06:02 +01:00
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
|
using Umbraco.Cms.Core.Persistence.Repositories;
|
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
|
namespace Umbraco.Cms.Core.Cache
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
public sealed class TemplateCacheRefresher : CacheRefresherBase<TemplateCacheRefresher>
|
|
|
|
|
|
{
|
2020-01-22 14:09:20 +01:00
|
|
|
|
private readonly IIdKeyMap _idKeyMap;
|
2019-07-29 08:31:49 +02:00
|
|
|
|
private readonly IContentTypeCommonRepository _contentTypeCommonRepository;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2020-01-22 14:09:20 +01: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
|
|
|
|
{
|
2020-01-22 14:09:20 +01:00
|
|
|
|
_idKeyMap = idKeyMap;
|
2019-07-29 08:31:49 +02:00
|
|
|
|
_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>();
|
2019-07-29 08:31:49 +02:00
|
|
|
|
_contentTypeCommonRepository.ClearCache();
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
|
|
base.Remove(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void RemoveFromCache(int id)
|
|
|
|
|
|
{
|
2020-01-22 14:09:20 +01:00
|
|
|
|
_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
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|