2013-03-21 22:53:58 +06:00
|
|
|
|
using System;
|
|
|
|
|
|
using Umbraco.Core.Events;
|
|
|
|
|
|
using Umbraco.Core.Sync;
|
2016-01-06 18:08:14 +01:00
|
|
|
|
using Umbraco.Core.Models.EntityBase;
|
2013-03-21 22:53:58 +06:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Cache
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A base class for cache refreshers to inherit from that ensures the correct events are raised
|
|
|
|
|
|
/// when cache refreshing occurs.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TInstanceType">The real cache refresher type, this is used for raising strongly typed events</typeparam>
|
|
|
|
|
|
public abstract class CacheRefresherBase<TInstanceType> : ICacheRefresher
|
|
|
|
|
|
where TInstanceType : ICacheRefresher
|
|
|
|
|
|
{
|
2016-05-18 18:44:08 +02:00
|
|
|
|
protected CacheRefresherBase(CacheHelper cacheHelper)
|
|
|
|
|
|
{
|
|
|
|
|
|
CacheHelper = cacheHelper;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-21 22:53:58 +06:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// An event that is raised when cache is updated on an individual server
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// This event will fire on each server configured for an Umbraco project whenever a cache refresher
|
|
|
|
|
|
/// is updated.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public static event TypedEventHandler<TInstanceType, CacheRefresherEventArgs> CacheUpdated;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Raises the event
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="args"></param>
|
|
|
|
|
|
protected static void OnCacheUpdated(TInstanceType sender, CacheRefresherEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CacheUpdated != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
CacheUpdated(sender, args);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns the real instance of the object ('this') for use in strongly typed events
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected abstract TInstanceType Instance { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public abstract Guid UniqueIdentifier { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public abstract string Name { get; }
|
|
|
|
|
|
|
2016-05-18 18:44:08 +02:00
|
|
|
|
protected CacheHelper CacheHelper { get; }
|
|
|
|
|
|
|
2013-03-21 22:53:58 +06:00
|
|
|
|
public virtual void RefreshAll()
|
|
|
|
|
|
{
|
|
|
|
|
|
OnCacheUpdated(Instance, new CacheRefresherEventArgs(null, MessageType.RefreshAll));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void Refresh(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnCacheUpdated(Instance, new CacheRefresherEventArgs(id, MessageType.RefreshById));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void Remove(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnCacheUpdated(Instance, new CacheRefresherEventArgs(id, MessageType.RemoveById));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void Refresh(Guid id)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnCacheUpdated(Instance, new CacheRefresherEventArgs(id, MessageType.RefreshById));
|
|
|
|
|
|
}
|
2016-01-06 18:08:14 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Clears the cache for all repository entities of this type
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TEntity"></typeparam>
|
2016-01-07 19:27:59 +01:00
|
|
|
|
internal void ClearAllIsolatedCacheByEntityType<TEntity>()
|
2016-01-06 18:08:14 +01:00
|
|
|
|
where TEntity : class, IAggregateRoot
|
|
|
|
|
|
{
|
2016-05-18 18:44:08 +02:00
|
|
|
|
CacheHelper.IsolatedRuntimeCache.ClearCache<TEntity>();
|
2016-01-06 18:08:14 +01:00
|
|
|
|
}
|
2013-03-21 22:53:58 +06:00
|
|
|
|
}
|
|
|
|
|
|
}
|