2020-09-23 12:54:13 +02:00
|
|
|
//using Newtonsoft.Json;
|
2021-02-18 11:06:02 +01:00
|
|
|
|
2020-07-31 00:19:36 +10:00
|
|
|
using System;
|
2021-03-12 21:48:24 +01:00
|
|
|
using Umbraco.Cms.Core.Events;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Persistence.Repositories;
|
|
|
|
|
using Umbraco.Cms.Core.Serialization;
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Extensions;
|
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
|
|
|
{
|
2021-03-12 21:48:24 +01:00
|
|
|
public sealed class MemberCacheRefresher : PayloadCacheRefresherBase<MemberCacheRefresherNotification, MemberCacheRefresher.JsonPayload>
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-01-22 14:09:20 +01:00
|
|
|
private readonly IIdKeyMap _idKeyMap;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2021-03-15 13:39:34 +11:00
|
|
|
public MemberCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IIdKeyMap idKeyMap, IEventAggregator eventAggregator, ICacheRefresherNotificationFactory factory)
|
|
|
|
|
: base(appCaches, serializer, eventAggregator, factory)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-01-22 14:09:20 +01:00
|
|
|
_idKeyMap = idKeyMap;
|
2020-07-31 00:19:36 +10:00
|
|
|
}
|
|
|
|
|
|
2020-09-23 12:54:13 +02:00
|
|
|
public class JsonPayload
|
2020-07-31 00:19:36 +10:00
|
|
|
{
|
2020-09-23 12:54:13 +02:00
|
|
|
//[JsonConstructor]
|
2021-03-05 15:36:27 +01:00
|
|
|
public JsonPayload(int id, string username, bool removed)
|
2020-07-31 00:19:36 +10:00
|
|
|
{
|
|
|
|
|
Id = id;
|
|
|
|
|
Username = username;
|
2021-03-05 15:36:27 +01:00
|
|
|
Removed = removed;
|
2020-07-31 00:19:36 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Id { get; }
|
|
|
|
|
public string Username { get; }
|
2021-03-05 15:36:27 +01:00
|
|
|
public bool Removed { get; }
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Define
|
|
|
|
|
|
|
|
|
|
public static readonly Guid UniqueId = Guid.Parse("E285DF34-ACDC-4226-AE32-C0CB5CF388DA");
|
|
|
|
|
|
|
|
|
|
public override Guid RefresherUniqueId => UniqueId;
|
|
|
|
|
|
|
|
|
|
public override string Name => "Member Cache Refresher";
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Refresher
|
|
|
|
|
|
2020-07-31 00:19:36 +10:00
|
|
|
public override void Refresh(JsonPayload[] payloads)
|
|
|
|
|
{
|
|
|
|
|
ClearCache(payloads);
|
|
|
|
|
base.Refresh(payloads);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
public override void Refresh(int id)
|
|
|
|
|
{
|
2021-03-05 15:36:27 +01:00
|
|
|
ClearCache(new JsonPayload(id, null, false));
|
2018-06-29 19:52:40 +02:00
|
|
|
base.Refresh(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Remove(int id)
|
|
|
|
|
{
|
2021-03-05 15:36:27 +01:00
|
|
|
ClearCache(new JsonPayload(id, null, false));
|
2018-06-29 19:52:40 +02:00
|
|
|
base.Remove(id);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 00:19:36 +10:00
|
|
|
private void ClearCache(params JsonPayload[] payloads)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-01-22 14:09:20 +01:00
|
|
|
AppCaches.ClearPartialViewCache();
|
2019-01-17 11:01:23 +01:00
|
|
|
var memberCache = AppCaches.IsolatedCaches.Get<IMember>();
|
2020-07-31 00:19:36 +10:00
|
|
|
|
|
|
|
|
foreach (var p in payloads)
|
|
|
|
|
{
|
2020-09-23 12:54:13 +02:00
|
|
|
_idKeyMap.ClearCache(p.Id);
|
2020-07-31 00:19:36 +10:00
|
|
|
if (memberCache)
|
|
|
|
|
{
|
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
|
|
|
memberCache.Result.Clear(RepositoryCacheKeys.GetKey<IMember, int>(p.Id));
|
|
|
|
|
memberCache.Result.Clear(RepositoryCacheKeys.GetKey<IMember, string>(p.Username));
|
2020-09-23 12:54:13 +02:00
|
|
|
}
|
2020-07-31 00:19:36 +10:00
|
|
|
}
|
2020-09-23 12:54:13 +02:00
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Indirect
|
|
|
|
|
|
2019-01-17 08:34:29 +01:00
|
|
|
public static void RefreshMemberTypes(AppCaches appCaches)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2019-01-17 11:01:23 +01:00
|
|
|
appCaches.IsolatedCaches.ClearCache<IMember>();
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|