Files
Umbraco-CMS/src/Umbraco.Core/Cache/MacroCacheRefresher.cs
Shannon Deminick a1624d26a3 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 07:11:45 +02:00

100 lines
2.6 KiB
C#

using System;
using System.Linq;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.Serialization;
namespace Umbraco.Cms.Core.Cache
{
public sealed class MacroCacheRefresher : PayloadCacheRefresherBase<MacroCacheRefresherNotification, MacroCacheRefresher.JsonPayload>
{
public MacroCacheRefresher(
AppCaches appCaches,
IJsonSerializer jsonSerializer,
IEventAggregator eventAggregator,
ICacheRefresherNotificationFactory factory)
: base(appCaches, jsonSerializer, eventAggregator, factory)
{
}
#region Define
public static readonly Guid UniqueId = Guid.Parse("7B1E683C-5F34-43dd-803D-9699EA1E98CA");
public override Guid RefresherUniqueId => UniqueId;
public override string Name => "Macro Cache Refresher";
#endregion
#region Refresher
public override void RefreshAll()
{
foreach (var prefix in GetAllMacroCacheKeys())
AppCaches.RuntimeCache.ClearByKey(prefix);
ClearAllIsolatedCacheByEntityType<IMacro>();
base.RefreshAll();
}
public override void Refresh(string json)
{
var payloads = Deserialize(json);
foreach (var payload in payloads)
{
foreach (var alias in GetCacheKeysForAlias(payload.Alias))
AppCaches.RuntimeCache.ClearByKey(alias);
var macroRepoCache = AppCaches.IsolatedCaches.Get<IMacro>();
if (macroRepoCache)
{
macroRepoCache.Result.Clear(RepositoryCacheKeys.GetKey<IMacro, int>(payload.Id));
}
}
base.Refresh(json);
}
#endregion
#region Json
public class JsonPayload
{
public JsonPayload(int id, string alias)
{
Id = id;
Alias = alias;
}
public int Id { get; }
public string Alias { get; }
}
#endregion
#region Helpers
internal static string[] GetAllMacroCacheKeys()
{
return new[]
{
CacheKeys.MacroContentCacheKey, // macro render cache
CacheKeys.MacroFromAliasCacheKey, // lookup macro by alias
};
}
internal static string[] GetCacheKeysForAlias(string alias)
{
return GetAllMacroCacheKeys().Select(x => x + alias).ToArray();
}
#endregion
}
}