2021-03-15 13:39:34 +11:00
|
|
|
using System;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Events;
|
|
|
|
|
using Umbraco.Cms.Core.Models.Entities;
|
|
|
|
|
using Umbraco.Cms.Core.Sync;
|
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
|
|
|
{
|
|
|
|
|
/// <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>
|
2021-03-15 13:39:34 +11:00
|
|
|
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>
|
2021-03-15 13:39:34 +11:00
|
|
|
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;
|
2021-03-12 21:48:24 +01:00
|
|
|
EventAggregator = eventAggregator;
|
2021-03-15 13:39:34 +11:00
|
|
|
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; }
|
|
|
|
|
|
2021-03-15 13:39:34 +11:00
|
|
|
/// <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)
|
|
|
|
|
{
|
2021-03-15 13:39:34 +11:00
|
|
|
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)
|
|
|
|
|
{
|
2021-03-15 13:39:34 +11:00
|
|
|
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)
|
|
|
|
|
{
|
2021-03-15 13:39:34 +11:00
|
|
|
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
|
|
|
|
2021-03-12 21:48:24 +01: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>
|
2021-03-15 13:39:34 +11:00
|
|
|
protected void OnCacheUpdated(CacheRefresherNotification notification)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2021-03-12 21:48:24 +01:00
|
|
|
EventAggregator.Publish(notification);
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|