AB4635 - Fixed up some of the review comments - Removed static (de)serializers and get the CacheRefresher from the collection

This commit is contained in:
Bjarke Berg
2020-01-22 14:09:20 +01:00
parent 17ee7796f4
commit 47c211907a
28 changed files with 120 additions and 138 deletions
@@ -15,14 +15,14 @@ namespace Umbraco.Web.Cache
public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCacheRefresher, ContentCacheRefresher.JsonPayload>
{
private readonly IPublishedSnapshotService _publishedSnapshotService;
private readonly IIdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
private readonly IDomainService _domainService;
public ContentCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IIdkMap idkMap, IDomainService domainService)
public ContentCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IIdKeyMap idKeyMap, IDomainService domainService)
: base(appCaches, serializer)
{
_publishedSnapshotService = publishedSnapshotService;
_idkMap = idkMap;
_idKeyMap = idKeyMap;
_domainService = domainService;
}
@@ -54,7 +54,7 @@ namespace Umbraco.Web.Cache
//By GUID Key
isolatedCache.Clear(RepositoryCacheKeys.GetKey<IContent>(payload.Key));
_idkMap.ClearCache(payload.Id);
_idKeyMap.ClearCache(payload.Id);
// remove those that are in the branch
if (payload.ChangeTypes.HasTypesAny(TreeChangeTypes.RefreshBranch | TreeChangeTypes.Remove))
@@ -17,14 +17,14 @@ namespace Umbraco.Web.Cache
private readonly IPublishedSnapshotService _publishedSnapshotService;
private readonly IPublishedModelFactory _publishedModelFactory;
private readonly IContentTypeCommonRepository _contentTypeCommonRepository;
private readonly IIdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
public ContentTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IIdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository)
public ContentTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IIdKeyMap idKeyMap, IContentTypeCommonRepository contentTypeCommonRepository)
: base(appCaches, serializer)
{
_publishedSnapshotService = publishedSnapshotService;
_publishedModelFactory = publishedModelFactory;
_idkMap = idkMap;
_idKeyMap = idKeyMap;
_contentTypeCommonRepository = contentTypeCommonRepository;
}
@@ -70,7 +70,7 @@ namespace Umbraco.Web.Cache
foreach (var id in payloads.Select(x => x.Id))
{
_idkMap.ClearCache(id);
_idKeyMap.ClearCache(id);
}
if (payloads.Any(x => x.ItemType == typeof(IContentType).Name))
@@ -15,14 +15,14 @@ namespace Umbraco.Web.Cache
{
private readonly IPublishedSnapshotService _publishedSnapshotService;
private readonly IPublishedModelFactory _publishedModelFactory;
private readonly IIdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
public DataTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IIdkMap idkMap)
public DataTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IIdKeyMap idKeyMap)
: base(appCaches, serializer)
{
_publishedSnapshotService = publishedSnapshotService;
_publishedModelFactory = publishedModelFactory;
_idkMap = idkMap;
_idKeyMap = idKeyMap;
}
#region Define
@@ -56,7 +56,7 @@ namespace Umbraco.Web.Cache
foreach (var payload in payloads)
{
_idkMap.ClearCache(payload.Id);
_idKeyMap.ClearCache(payload.Id);
}
// TODO: not sure I like these?
@@ -1,4 +1,5 @@
using Umbraco.Core.Sync;
using Umbraco.Core.Serialization;
using Umbraco.Core.Sync;
namespace Umbraco.Core.Cache
{
@@ -7,15 +8,19 @@ namespace Umbraco.Core.Cache
/// </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 JsonCacheRefresherBase<TInstanceType> : CacheRefresherBase<TInstanceType>, IJsonCacheRefresher
public abstract class JsonCacheRefresherBase<TInstanceType, TJsonPayload> : CacheRefresherBase<TInstanceType>, IJsonCacheRefresher
where TInstanceType : class, ICacheRefresher
{
protected IJsonSerializer JsonSerializer { get; }
/// <summary>
/// Initializes a new instance of the <see cref="JsonCacheRefresherBase{TInstanceType}"/>.
/// </summary>
/// <param name="appCaches">A cache helper.</param>
protected JsonCacheRefresherBase(AppCaches appCaches) : base(appCaches)
{ }
protected JsonCacheRefresherBase(AppCaches appCaches, IJsonSerializer jsonSerializer) : base(appCaches)
{
JsonSerializer = jsonSerializer;
}
/// <summary>
/// Refreshes as specified by a json payload.
@@ -25,5 +30,24 @@ namespace Umbraco.Core.Cache
{
OnCacheUpdated(This, new CacheRefresherEventArgs(json, MessageType.RefreshByJson));
}
#region Json
/// <summary>
/// Deserializes a json payload into an object payload.
/// </summary>
/// <param name="json">The json payload.</param>
/// <returns>The deserialized object payload.</returns>
public TJsonPayload[] Deserialize(string json)
{
return JsonSerializer.Deserialize<TJsonPayload[]>(json);
}
public string Serialize(params TJsonPayload[] jsonPayloads)
{
return JsonSerializer.Serialize(jsonPayloads);
}
#endregion
}
}
@@ -7,14 +7,12 @@ using Umbraco.Core.Serialization;
namespace Umbraco.Web.Cache
{
public sealed class MacroCacheRefresher : JsonCacheRefresherBase<MacroCacheRefresher>
public sealed class MacroCacheRefresher : JsonCacheRefresherBase<MacroCacheRefresher, MacroCacheRefresher.JsonPayload>
{
private readonly IJsonSerializer _jsonSerializer;
public MacroCacheRefresher(AppCaches appCaches, IJsonSerializer jsonSerializer)
: base(appCaches)
: base(appCaches, jsonSerializer)
{
_jsonSerializer = jsonSerializer;
}
#region Define
@@ -43,7 +41,7 @@ namespace Umbraco.Web.Cache
public override void Refresh(string json)
{
var payloads = Deserialize(_jsonSerializer, json);
var payloads = Deserialize(json);
foreach (var payload in payloads)
{
@@ -59,7 +57,6 @@ namespace Umbraco.Web.Cache
base.Refresh(json);
}
#endregion
#region Json
@@ -77,17 +74,6 @@ namespace Umbraco.Web.Cache
public string Alias { get; }
}
public static JsonPayload[] Deserialize(IJsonSerializer jsonSerializer, string json)
{
return jsonSerializer.Deserialize<JsonPayload[]>(json);
}
public static string Serialize( IJsonSerializer jsonSerializer, params IMacro[] macros)
{
return jsonSerializer.Serialize(macros.Select(x => new JsonPayload(x.Id, x.Alias)).ToArray());
}
#endregion
#region Helpers
@@ -12,16 +12,14 @@ namespace Umbraco.Web.Cache
{
public sealed class MediaCacheRefresher : PayloadCacheRefresherBase<MediaCacheRefresher, MediaCacheRefresher.JsonPayload>
{
private readonly AppCaches _appCaches;
private readonly IPublishedSnapshotService _publishedSnapshotService;
private readonly IIdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
public MediaCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IIdkMap idkMap)
public MediaCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IIdKeyMap idKeyMap)
: base(appCaches, serializer)
{
_appCaches = appCaches;
_publishedSnapshotService = publishedSnapshotService;
_idkMap = idkMap;
_idKeyMap = idKeyMap;
}
#region Define
@@ -46,14 +44,14 @@ namespace Umbraco.Web.Cache
if (anythingChanged)
{
_appCaches.ClearPartialViewCache();
AppCaches.ClearPartialViewCache();
var mediaCache = AppCaches.IsolatedCaches.Get<IMedia>();
foreach (var payload in payloads)
{
if (payload.ChangeTypes == TreeChangeTypes.Remove)
_idkMap.ClearCache(payload.Id);
_idKeyMap.ClearCache(payload.Id);
if (!mediaCache) continue;
@@ -10,14 +10,12 @@ namespace Umbraco.Web.Cache
{
public sealed class MemberCacheRefresher : TypedCacheRefresherBase<MemberCacheRefresher, IMember>
{
private readonly AppCaches _appCaches;
private readonly IIdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
public MemberCacheRefresher(AppCaches appCaches, IIdkMap idkMap)
public MemberCacheRefresher(AppCaches appCaches, IIdKeyMap idKeyMap)
: base(appCaches)
{
_appCaches = appCaches;
_idkMap = idkMap;
_idKeyMap = idKeyMap;
}
#region Define
@@ -60,8 +58,8 @@ namespace Umbraco.Web.Cache
private void ClearCache(int id)
{
_idkMap.ClearCache(id);
_appCaches.ClearPartialViewCache();
_idKeyMap.ClearCache(id);
AppCaches.ClearPartialViewCache();
var memberCache = AppCaches.IsolatedCaches.Get<IMember>();
if (memberCache)
@@ -6,14 +6,12 @@ using Umbraco.Core.Serialization;
namespace Umbraco.Web.Cache
{
public sealed class MemberGroupCacheRefresher : JsonCacheRefresherBase<MemberGroupCacheRefresher>
public sealed class MemberGroupCacheRefresher : JsonCacheRefresherBase<MemberGroupCacheRefresher, MemberGroupCacheRefresher.JsonPayload>
{
private readonly IJsonSerializer _jsonSerializer;
public MemberGroupCacheRefresher(AppCaches appCaches, IJsonSerializer jsonSerializer)
: base(appCaches)
: base(appCaches, jsonSerializer)
{
_jsonSerializer = jsonSerializer;
}
#region Define
@@ -72,15 +70,15 @@ namespace Umbraco.Web.Cache
public int Id { get; }
}
private JsonPayload[] Deserialize(string json)
{
return _jsonSerializer.Deserialize<JsonPayload[]>(json);
}
private string Serialize(params IMemberGroup[] groups)
{
return _jsonSerializer.Serialize(groups.Select(x => new JsonPayload(x.Id, x.Name)).ToArray());
}
// private JsonPayload[] Deserialize(string json)
// {
// return _jsonSerializer.Deserialize<JsonPayload[]>(json);
// }
//
// private string Serialize(params IMemberGroup[] groups)
// {
// return _jsonSerializer.Serialize(groups.Select(x => new JsonPayload(x.Id, x.Name)).ToArray());
// }
#endregion
}
@@ -10,34 +10,19 @@ namespace Umbraco.Core.Cache
/// <typeparam name="TInstanceType">The actual cache refresher type.</typeparam>
/// <typeparam name="TPayload">The payload type.</typeparam>
/// <remarks>The actual cache refresher type is used for strongly typed events.</remarks>
public abstract class PayloadCacheRefresherBase<TInstanceType, TPayload> : JsonCacheRefresherBase<TInstanceType>, IPayloadCacheRefresher<TPayload>
public abstract class PayloadCacheRefresherBase<TInstanceType, TPayload> : JsonCacheRefresherBase<TInstanceType, TPayload>, IPayloadCacheRefresher<TPayload>
where TInstanceType : class, ICacheRefresher
{
private readonly IJsonSerializer _serializer;
/// <summary>
/// Initializes a new instance of the <see cref="PayloadCacheRefresherBase{TInstanceType, TPayload}"/>.
/// </summary>
/// <param name="appCaches">A cache helper.</param>
/// <param name="serializer"></param>
protected PayloadCacheRefresherBase(AppCaches appCaches, IJsonSerializer serializer) : base(appCaches)
protected PayloadCacheRefresherBase(AppCaches appCaches, IJsonSerializer serializer) : base(appCaches, serializer)
{
_serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
}
#region Json
/// <summary>
/// Deserializes a json payload into an object payload.
/// </summary>
/// <param name="json">The json payload.</param>
/// <returns>The deserialized object payload.</returns>
protected virtual TPayload[] Deserialize(string json)
{
return _serializer.Deserialize<TPayload[]>(json);
}
#endregion
#region Refresher
@@ -8,13 +8,13 @@ namespace Umbraco.Web.Cache
{
public sealed class TemplateCacheRefresher : CacheRefresherBase<TemplateCacheRefresher>
{
private readonly IIdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
private readonly IContentTypeCommonRepository _contentTypeCommonRepository;
public TemplateCacheRefresher(AppCaches appCaches, IIdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository)
public TemplateCacheRefresher(AppCaches appCaches, IIdKeyMap idKeyMap, IContentTypeCommonRepository contentTypeCommonRepository)
: base(appCaches)
{
_idkMap = idkMap;
_idKeyMap = idKeyMap;
_contentTypeCommonRepository = contentTypeCommonRepository;
}
@@ -55,7 +55,7 @@ namespace Umbraco.Web.Cache
private void RemoveFromCache(int id)
{
_idkMap.ClearCache(id);
_idKeyMap.ClearCache(id);
AppCaches.RuntimeCache.Clear($"{CacheKeys.TemplateFrontEndCacheKey}{id}");
//need to clear the runtime cache for templates
@@ -3,7 +3,7 @@ using Umbraco.Core.Models;
namespace Umbraco.Core.Services
{
public interface IIdkMap
public interface IIdKeyMap
{
void SetMapper(UmbracoObjectTypes umbracoObjectType, Func<int, Guid> id2key, Func<Guid, int> key2id);
Attempt<int> GetIdForKey(Guid key, UmbracoObjectTypes umbracoObjectType);
@@ -14,4 +14,4 @@ namespace Umbraco.Core.Services
void ClearCache(int id);
void ClearCache(Guid key);
}
}
}
@@ -24,7 +24,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions
composition.RegisterUnique<ServiceContext>();
// register the special idk map
composition.RegisterUnique<IIdkMap, IdkMap>();
composition.RegisterUnique<IIdKeyMap, IdKeyMap>();
// register the services
composition.RegisterUnique<IPropertyValidationService, PropertyValidationService>();
@@ -7,8 +7,7 @@ using Umbraco.Core.Scoping;
namespace Umbraco.Core.Services
{
//Todo rename to IdKeyMap
public class IdkMap : IIdkMap
public class IdKeyMap : IIdKeyMap
{
private readonly IScopeProvider _scopeProvider;
private readonly ReaderWriterLockSlim _locker = new ReaderWriterLockSlim();
@@ -16,7 +15,7 @@ namespace Umbraco.Core.Services
private readonly Dictionary<int, TypedId<Guid>> _id2Key = new Dictionary<int, TypedId<Guid>>();
private readonly Dictionary<Guid, TypedId<int>> _key2Id = new Dictionary<Guid, TypedId<int>>();
public IdkMap(IScopeProvider scopeProvider)
public IdKeyMap(IScopeProvider scopeProvider)
{
_scopeProvider = scopeProvider;
}
@@ -19,12 +19,12 @@ namespace Umbraco.Core.Services.Implement
private readonly IEntityRepository _entityRepository;
private readonly Dictionary<string, UmbracoObjectTypes> _objectTypes;
private IQuery<IUmbracoEntity> _queryRootEntity;
private readonly IIdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
public EntityService(IScopeProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IIdkMap idkMap, IEntityRepository entityRepository)
public EntityService(IScopeProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IIdKeyMap idKeyMap, IEntityRepository entityRepository)
: base(provider, logger, eventMessagesFactory)
{
_idkMap = idkMap;
_idKeyMap = idKeyMap;
_entityRepository = entityRepository;
_objectTypes = new Dictionary<string, UmbracoObjectTypes>
@@ -440,19 +440,19 @@ namespace Umbraco.Core.Services.Implement
/// <inheritdoc />
public Attempt<int> GetId(Guid key, UmbracoObjectTypes objectType)
{
return _idkMap.GetIdForKey(key, objectType);
return _idKeyMap.GetIdForKey(key, objectType);
}
/// <inheritdoc />
public Attempt<int> GetId(Udi udi)
{
return _idkMap.GetIdForUdi(udi);
return _idKeyMap.GetIdForUdi(udi);
}
/// <inheritdoc />
public Attempt<Guid> GetKey(int id, UmbracoObjectTypes umbracoObjectType)
{
return _idkMap.GetKeyForId(id, umbracoObjectType);
return _idKeyMap.GetKeyForId(id, umbracoObjectType);
}
/// <inheritdoc />
@@ -70,10 +70,6 @@
<Project>{29aa69d9-b597-4395-8d42-43b1263c240a}</Project>
<Name>Umbraco.Abstractions</Name>
</ProjectReference>
<ProjectReference Include="..\Umbraco.Core\Umbraco.Core.csproj">
<Project>{31785bc3-256c-4613-b2f5-a1b0bdded8c1}</Project>
<Name>Umbraco.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Umbraco.Examine\Umbraco.Examine.csproj">
<Project>{07fbc26b-2927-4a22-8d96-d644c667fecc}</Project>
<Name>Umbraco.Examine</Name>
@@ -3,6 +3,7 @@ using System.Linq;
using System.Threading;
using Moq;
using NUnit.Framework;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
@@ -165,7 +166,7 @@ namespace Umbraco.Tests.Cache
IOHelper);
// just assert it does not throw
var refreshers = new DistributedCacheBinder(null, umbracoContextFactory, null, JsonNetSerializer);
var refreshers = new DistributedCacheBinder(null, umbracoContextFactory, null, new CacheRefresherCollection(Array.Empty<ICacheRefresher>()));
refreshers.HandleEvents(definitions);
}
}
@@ -33,7 +33,7 @@ namespace Umbraco.Tests.Integration
{
base.SetUp();
_h1 = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), JsonNetSerializer);
_h1 = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), Current.CacheRefreshers);
_h1.BindEvents(true);
_events = new List<EventInstance>();
@@ -141,7 +141,7 @@ namespace Umbraco.Tests.Scoping
var umbracoContext = GetUmbracoContextNu("http://example.com/", setSingleton: true);
// wire cache refresher
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), JsonNetSerializer);
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), Current.CacheRefreshers);
_distributedCacheBinder.BindEvents(true);
// create document type, document
@@ -75,7 +75,7 @@ namespace Umbraco.Tests.Scoping
// get user again - else we'd modify the one that's in the cache
user = service.GetUserById(user.Id);
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), JsonNetSerializer);
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), Current.CacheRefreshers);
_distributedCacheBinder.BindEvents(true);
Assert.IsNull(scopeProvider.AmbientScope);
@@ -156,7 +156,7 @@ namespace Umbraco.Tests.Scoping
Assert.AreEqual(lang.Id, globalCached.Id);
Assert.AreEqual("fr-FR", globalCached.IsoCode);
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), JsonNetSerializer);
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), Current.CacheRefreshers);
_distributedCacheBinder.BindEvents(true);
Assert.IsNull(scopeProvider.AmbientScope);
@@ -248,7 +248,7 @@ namespace Umbraco.Tests.Scoping
Assert.AreEqual(item.Id, globalCached.Id);
Assert.AreEqual("item-key", globalCached.ItemKey);
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), JsonNetSerializer);
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), Current.CacheRefreshers);
_distributedCacheBinder.BindEvents(true);
Assert.IsNull(scopeProvider.AmbientScope);
+2 -2
View File
@@ -93,7 +93,7 @@ namespace Umbraco.Tests.Scoping
var item = new Content("name", -1, contentType);
// wire cache refresher
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), JsonNetSerializer);
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), Current.CacheRefreshers);
_distributedCacheBinder.BindEvents(true);
// check xml in context = "before"
@@ -206,7 +206,7 @@ namespace Umbraco.Tests.Scoping
Current.Services.ContentTypeService.Save(contentType);
// wire cache refresher
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), JsonNetSerializer);
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), Current.CacheRefreshers);
_distributedCacheBinder.BindEvents(true);
// check xml in context = "before"
+1 -1
View File
@@ -152,7 +152,7 @@ namespace Umbraco.Tests.TestHelpers
logger));
var runtimeState = Mock.Of<IRuntimeState>();
var idkMap = new IdkMap(scopeProvider);
var idkMap = new IdKeyMap(scopeProvider);
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
-4
View File
@@ -562,10 +562,6 @@
<Project>{fbe7c065-dac0-4025-a78b-63b24d3ab00b}</Project>
<Name>Umbraco.Configuration</Name>
</ProjectReference>
<ProjectReference Include="..\Umbraco.Core\Umbraco.Core.csproj">
<Project>{31785BC3-256C-4613-B2F5-A1B0BDDED8C1}</Project>
<Name>Umbraco.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Umbraco.Infrastructure\Umbraco.Infrastructure.csproj">
<Project>{3ae7bf57-966b-45a5-910a-954d7c554441}</Project>
<Name>Umbraco.Infrastructure</Name>
+1 -5
View File
@@ -117,10 +117,6 @@
<Project>{29aa69d9-b597-4395-8d42-43b1263c240a}</Project>
<Name>Umbraco.Abstractions</Name>
</ProjectReference>
<ProjectReference Include="..\Umbraco.Core\Umbraco.Core.csproj">
<Project>{31785bc3-256c-4613-b2f5-a1b0bdded8c1}</Project>
<Name>Umbraco.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Umbraco.Examine\Umbraco.Examine.csproj">
<Name>Umbraco.Examine</Name>
<Project>{07FBC26B-2927-4A22-8D96-D644C667FECC}</Project>
@@ -436,4 +432,4 @@
<Message Text="ConfigFile: $(OriginalFileName) -&gt; $(OutputFileName)" Importance="high" Condition="Exists('$(ModifiedFileName)')" />
<Copy SourceFiles="$(ModifiedFileName)" DestinationFiles="$(OutputFileName)" OverwriteReadOnlyFiles="true" SkipUnchangedFiles="false" Condition="Exists('$(ModifiedFileName)')" />
</Target>
</Project>
</Project>
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Events;
using Umbraco.Core.Logging;
using Umbraco.Core.Serialization;
@@ -19,16 +20,16 @@ namespace Umbraco.Web.Cache
private readonly DistributedCache _distributedCache;
private readonly IUmbracoContextFactory _umbracoContextFactory;
private readonly ILogger _logger;
private readonly IJsonSerializer _jsonSerializer;
private readonly CacheRefresherCollection _cacheRefresherCollection;
/// <summary>
/// Initializes a new instance of the <see cref="DistributedCacheBinder"/> class.
/// </summary>
public DistributedCacheBinder(DistributedCache distributedCache, IUmbracoContextFactory umbracoContextFactory, ILogger logger, IJsonSerializer jsonSerializer)
public DistributedCacheBinder(DistributedCache distributedCache, IUmbracoContextFactory umbracoContextFactory, ILogger logger, CacheRefresherCollection cacheRefresherCollection)
{
_distributedCache = distributedCache;
_logger = logger;
_jsonSerializer = jsonSerializer;
_cacheRefresherCollection = cacheRefresherCollection;
_umbracoContextFactory = umbracoContextFactory;
}
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Cache;
using Umbraco.Core.Events;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
@@ -103,10 +104,10 @@ namespace Umbraco.Web.Cache
() => FileService.DeletedTemplate -= FileService_DeletedTemplate);
// bind to macro events
Bind(() => MacroService.Saved += MacroService_Saved,
() => MacroService.Saved -= MacroService_Saved);
Bind(() => MacroService.Deleted += MacroService_Deleted,
() => MacroService.Deleted -= MacroService_Deleted);
Bind(() => MacroService.Saved += (sender, e) => MacroService_Saved(sender, e),
() => MacroService.Saved -= (sender, e) => MacroService_Saved(sender, e));
Bind(() => MacroService.Deleted += (sender, e) => MacroService_Deleted(sender, e),
() => MacroService.Deleted -= (sender, e) => MacroService_Deleted(sender, e));
// bind to member events
Bind(() => MemberService.Saved += MemberService_Saved,
@@ -349,6 +350,7 @@ namespace Umbraco.Web.Cache
private void UserService_DeletedUserGroup(IUserService sender, DeleteEventArgs<IUserGroup> e)
{
foreach (var entity in e.DeletedEntities)
_distributedCache.RemoveUserGroupCache(entity.Id);
}
@@ -387,16 +389,18 @@ namespace Umbraco.Web.Cache
#region MacroService
private MacroCacheRefresher MacroCacheRefresher => _cacheRefresherCollection[MacroCacheRefresher.UniqueId] as MacroCacheRefresher;
private void MacroService_Deleted(IMacroService sender, DeleteEventArgs<IMacro> e)
{
foreach (var entity in e.DeletedEntities)
_distributedCache.RemoveMacroCache(_jsonSerializer, entity);
_distributedCache.RemoveMacroCache(MacroCacheRefresher, entity);
}
private void MacroService_Saved(IMacroService sender, SaveEventArgs<IMacro> e)
{
foreach (var entity in e.SavedEntities)
_distributedCache.RefreshMacroCache(_jsonSerializer, entity);
_distributedCache.RefreshMacroCache(MacroCacheRefresher, entity);
}
#endregion
@@ -1,4 +1,6 @@
using System.Linq;
using NPoco.Expressions;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
using Umbraco.Core.Serialization;
using Umbraco.Core.Services.Changes;
@@ -190,16 +192,16 @@ namespace Umbraco.Web.Cache
#region MacroCache
public static void RefreshMacroCache(this DistributedCache dc, IJsonSerializer jsonSerializer, IMacro macro)
public static void RefreshMacroCache(this DistributedCache dc, MacroCacheRefresher macroCacheRefresher, IMacro macro)
{
if (macro == null) return;
dc.RefreshByJson(MacroCacheRefresher.UniqueId, MacroCacheRefresher.Serialize(jsonSerializer, macro));
dc.RefreshByJson(macroCacheRefresher.RefresherUniqueId, macroCacheRefresher.Serialize(new MacroCacheRefresher.JsonPayload(macro.Id, macro.Alias)));
}
public static void RemoveMacroCache(this DistributedCache dc, IJsonSerializer jsonSerializer, IMacro macro)
public static void RemoveMacroCache(this DistributedCache dc, MacroCacheRefresher macroCacheRefresher, IMacro macro)
{
if (macro == null) return;
dc.RefreshByJson(MacroCacheRefresher.UniqueId, MacroCacheRefresher.Serialize(jsonSerializer, macro));
dc.RefreshByJson(macroCacheRefresher.RefresherUniqueId, macroCacheRefresher.Serialize(new MacroCacheRefresher.JsonPayload(macro.Id, macro.Alias)));
}
#endregion
@@ -299,5 +301,7 @@ namespace Umbraco.Web.Cache
}
#endregion
}
}
@@ -76,7 +76,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
//private static int _singletonCheck;
public PublishedSnapshotService(PublishedSnapshotServiceOptions options, IMainDom mainDom, IRuntimeState runtime,
ServiceContext serviceContext, IPublishedContentTypeFactory publishedContentTypeFactory, IIdkMap idkMap,
ServiceContext serviceContext, IPublishedContentTypeFactory publishedContentTypeFactory, IIdKeyMap idKeyMap,
IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IProfilingLogger logger, IScopeProvider scopeProvider,
IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository,
IDefaultCultureAccessor defaultCultureAccessor,
@@ -160,10 +160,10 @@ namespace Umbraco.Web.PublishedCache.NuCache
Guid GetUid(ContentStore store, int id) => store.LiveSnapshot.Get(id)?.Uid ?? default;
int GetId(ContentStore store, Guid uid) => store.LiveSnapshot.Get(uid)?.Id ?? default;
if (idkMap != null)
if (idKeyMap != null)
{
idkMap.SetMapper(UmbracoObjectTypes.Document, id => GetUid(_contentStore, id), uid => GetId(_contentStore, uid));
idkMap.SetMapper(UmbracoObjectTypes.Media, id => GetUid(_mediaStore, id), uid => GetId(_mediaStore, uid));
idKeyMap.SetMapper(UmbracoObjectTypes.Document, id => GetUid(_contentStore, id), uid => GetId(_contentStore, uid));
idKeyMap.SetMapper(UmbracoObjectTypes.Media, id => GetUid(_mediaStore, id), uid => GetId(_mediaStore, uid));
}
}
-4
View File
@@ -107,10 +107,6 @@
<Project>{fbe7c065-dac0-4025-a78b-63b24d3ab00b}</Project>
<Name>Umbraco.Configuration</Name>
</ProjectReference>
<ProjectReference Include="..\Umbraco.Core\Umbraco.Core.csproj">
<Project>{31785bc3-256c-4613-b2f5-a1b0bdded8c1}</Project>
<Name>Umbraco.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Umbraco.Examine\Umbraco.Examine.csproj">
<Name>Umbraco.Examine</Name>
<Project>{07FBC26B-2927-4A22-8D96-D644C667FECC}</Project>