2013-02-06 09:53:13 +06:00
|
|
|
|
using System;
|
|
|
|
|
|
using Umbraco.Core;
|
2013-03-12 03:00:42 +04:00
|
|
|
|
using Umbraco.Core.Cache;
|
2013-07-23 11:46:18 +10:00
|
|
|
|
using Umbraco.Core.Models;
|
2015-01-13 13:33:39 +11:00
|
|
|
|
|
2013-02-06 09:53:13 +06:00
|
|
|
|
using umbraco;
|
|
|
|
|
|
using umbraco.interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Cache
|
|
|
|
|
|
{
|
2013-03-18 21:18:22 +06:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A cache refresher to ensure template cache is updated when members change
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <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>
|
2013-03-21 22:53:58 +06:00
|
|
|
|
public class TemplateCacheRefresher : CacheRefresherBase<TemplateCacheRefresher>
|
2013-02-06 09:53:13 +06:00
|
|
|
|
{
|
2013-03-21 22:53:58 +06:00
|
|
|
|
protected override TemplateCacheRefresher Instance
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return this; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string Name
|
2013-02-06 09:53:13 +06:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return "Template cache refresher";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-21 22:53:58 +06:00
|
|
|
|
public override Guid UniqueIdentifier
|
2013-02-06 09:53:13 +06:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2013-02-07 03:49:45 +06:00
|
|
|
|
return new Guid(DistributedCache.TemplateRefresherId);
|
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)
|
|
|
|
|
|
{
|
2015-05-12 12:39:46 +10:00
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.IdToKeyCacheKey);
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.KeyToIdCacheKey);
|
2015-01-13 13:25:36 +11:00
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(
|
2013-03-22 02:08:55 +06:00
|
|
|
|
string.Format("{0}{1}", CacheKeys.TemplateFrontEndCacheKey, id));
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|