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

122 lines
4.2 KiB
C#
Raw Normal View History

using System;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Core.Sync;
2018-06-29 19:52:40 +02:00
namespace Umbraco.Cms.Core.Cache
2018-06-29 19:52:40 +02:00
{
/// <summary>
/// A base class for cache refreshers that handles events.
/// </summary>
/// <typeparam name="TInstanceType">The actual cache refresher type.</typeparam>
/// <remarks>The actual cache refresher type is used for strongly typed events.</remarks>
public abstract class CacheRefresherBase<TNotification> : ICacheRefresher
where TNotification : CacheRefresherNotification
2018-06-29 19:52:40 +02:00
{
/// <summary>
/// Initializes a new instance of the <see cref="CacheRefresherBase{TInstanceType}"/>.
/// </summary>
2019-01-17 08:34:29 +01:00
/// <param name="appCaches">A cache helper.</param>
protected CacheRefresherBase(AppCaches appCaches, IEventAggregator eventAggregator, ICacheRefresherNotificationFactory factory)
2018-06-29 19:52:40 +02:00
{
2019-01-17 08:34:29 +01:00
AppCaches = appCaches;
EventAggregator = eventAggregator;
NotificationFactory = factory;
2018-06-29 19:52:40 +02:00
}
#region Define
/// <summary>
/// Gets the unique identifier of the refresher.
/// </summary>
public abstract Guid RefresherUniqueId { get; }
/// <summary>
/// Gets the name of the refresher.
/// </summary>
public abstract string Name { get; }
/// <summary>
/// Gets the <see cref="TNotificationFactory"/> for <see cref="TNotification"/>
/// </summary>
protected ICacheRefresherNotificationFactory NotificationFactory { get; }
2018-06-29 19:52:40 +02:00
#endregion
#region Refresher
/// <summary>
/// Refreshes all entities.
/// </summary>
public virtual void RefreshAll()
{
Implements Public Access in netcore (#10137) * Getting new netcore PublicAccessChecker in place * Adds full test coverage for PublicAccessChecker * remove PublicAccessComposer * adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller * Implements the required methods on IMemberManager, removes old migrated code * Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops * adds note * adds note * Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling. * Changes name to IUmbracoEndpointBuilder * adds note * Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect * fixing build * Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware. * adds note * removes unused filter, fixes build * fixes WebPath and tests * Looks up entities in one query * remove usings * Fix test, remove stylesheet * Set status code before we write to response to avoid error * Ensures that users and members are validated when logging in. Shares more code between users and members. * Fixes RepositoryCacheKeys to ensure the keys are normalized * oops didn't mean to commit this * Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy * bah, far out this keeps getting recommitted. sorry Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 15:11:45 +10:00
// NOTE: We pass in string.Empty here because if we pass in NULL this causes problems with
// the underlying ActivatorUtilities.CreateInstance which doesn't seem to support passing in
// null to an 'object' parameter and we end up with "A suitable constructor for type 'ZYZ' could not be located."
// In this case, all cache refreshers should be checking for the type first before checking for a msg value
// so this shouldn't cause any issues.
OnCacheUpdated(NotificationFactory.Create<TNotification>(string.Empty, MessageType.RefreshAll));
2018-06-29 19:52:40 +02:00
}
/// <summary>
/// Refreshes an entity.
/// </summary>
/// <param name="id">The entity's identifier.</param>
public virtual void Refresh(int id)
{
OnCacheUpdated(NotificationFactory.Create<TNotification>(id, MessageType.RefreshById));
2018-06-29 19:52:40 +02:00
}
/// <summary>
/// Refreshes an entity.
/// </summary>
/// <param name="id">The entity's identifier.</param>
public virtual void Refresh(Guid id)
{
OnCacheUpdated(NotificationFactory.Create<TNotification>(id, MessageType.RefreshById));
2018-06-29 19:52:40 +02:00
}
/// <summary>
/// Removes an entity.
/// </summary>
/// <param name="id">The entity's identifier.</param>
public virtual void Remove(int id)
{
OnCacheUpdated(NotificationFactory.Create<TNotification>(id, MessageType.RemoveById));
2018-06-29 19:52:40 +02:00
}
#endregion
#region Protected
/// <summary>
/// Gets the cache helper.
/// </summary>
2019-01-17 08:34:29 +01:00
protected AppCaches AppCaches { get; }
2018-06-29 19:52:40 +02:00
protected IEventAggregator EventAggregator { get; }
2018-06-29 19:52:40 +02:00
/// <summary>
/// Clears the cache for all repository entities of a specified type.
/// </summary>
/// <typeparam name="TEntity">The type of the entities.</typeparam>
protected void ClearAllIsolatedCacheByEntityType<TEntity>()
where TEntity : class, IEntity
{
2019-01-17 11:01:23 +01:00
AppCaches.IsolatedCaches.ClearCache<TEntity>();
2018-06-29 19:52:40 +02:00
}
/// <summary>
/// Raises the CacheUpdated event.
/// </summary>
/// <param name="sender">The event sender.</param>
/// <param name="args">The event arguments.</param>
protected void OnCacheUpdated(CacheRefresherNotification notification)
2018-06-29 19:52:40 +02:00
{
EventAggregator.Publish(notification);
2018-06-29 19:52:40 +02:00
}
#endregion
}
}