Merge pull request #7486 from umbraco/netcore/feature/AB4635-move-cache-refreshers

NetCore:  Moved CacheRefreshers to abstractions
This commit is contained in:
Shannon Deminick
2020-01-23 20:18:48 +11:00
committed by GitHub
62 changed files with 183 additions and 211 deletions
@@ -12,5 +12,7 @@
public const string MacroContentCacheKey = "macroContent_"; // used in MacroRenderers
public const string MacroFromAliasCacheKey = "macroFromAlias_";
public const string UserGroupGetByAliasCacheKeyPrefix = "UserGroupRepository_GetByAlias_";
}
}
@@ -1,17 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.Repositories.Implement;
using Umbraco.Core.Serialization;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Changes;
using Umbraco.Web.Composing;
using Umbraco.Web.PublishedCache;
namespace Umbraco.Web.Cache
@@ -19,14 +15,14 @@ namespace Umbraco.Web.Cache
public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCacheRefresher, ContentCacheRefresher.JsonPayload>
{
private readonly IPublishedSnapshotService _publishedSnapshotService;
private readonly IdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
private readonly IDomainService _domainService;
public ContentCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IdkMap 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;
}
@@ -58,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))
@@ -141,7 +137,6 @@ namespace Umbraco.Web.Cache
public class JsonPayload
{
[JsonConstructor]
public JsonPayload(int id, Guid? key, TreeChangeTypes changeTypes)
{
Id = id;
@@ -17,14 +17,14 @@ namespace Umbraco.Web.Cache
private readonly IPublishedSnapshotService _publishedSnapshotService;
private readonly IPublishedModelFactory _publishedModelFactory;
private readonly IContentTypeCommonRepository _contentTypeCommonRepository;
private readonly IdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
public ContentTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap 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 IdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
public DataTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap 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?
@@ -4,7 +4,6 @@ using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Sync;
using Umbraco.Web.Composing;
namespace Umbraco.Web.Cache
{
@@ -102,19 +101,6 @@ namespace Umbraco.Web.Cache
GetRefresherById(refresherGuid),
payloads.ToArray());
}
/// <summary>
/// Notifies the distributed cache, for a specified <see cref="ICacheRefresher"/>.
/// </summary>
/// <param name="refresherGuid">The unique identifier of the ICacheRefresher.</param>
/// <param name="jsonPayload">The notification content.</param>
public void RefreshByJson(Guid refresherGuid, string jsonPayload)
{
if (refresherGuid == Guid.Empty || jsonPayload.IsNullOrWhiteSpace()) return;
_serverMessenger.PerformRefresh(
GetRefresherById(refresherGuid),
jsonPayload);
}
///// <summary>
///// Notifies the distributed cache, for a specified <see cref="ICacheRefresher"/>.
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using Umbraco.Core.Events;
using Umbraco.Core.Services.Implement;
namespace Umbraco.Web.Cache
{
@@ -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
}
}
@@ -11,8 +11,6 @@ using static Umbraco.Web.Cache.LanguageCacheRefresher.JsonPayload;
namespace Umbraco.Web.Cache
{
public sealed class LanguageCacheRefresher : PayloadCacheRefresherBase<LanguageCacheRefresher, LanguageCacheRefresher.JsonPayload>
//CacheRefresherBase<LanguageCacheRefresher>
{
public LanguageCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService)
: base(appCaches, serializer)
@@ -1,19 +1,19 @@
using System;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Repositories;
using System.Linq;
using Newtonsoft.Json;
using Umbraco.Core.Persistence.Repositories.Implement;
using Umbraco.Core.Serialization;
namespace Umbraco.Web.Cache
{
public sealed class MacroCacheRefresher : JsonCacheRefresherBase<MacroCacheRefresher>
public sealed class MacroCacheRefresher : JsonCacheRefresherBase<MacroCacheRefresher, MacroCacheRefresher.JsonPayload>
{
public MacroCacheRefresher(AppCaches appCaches)
: base(appCaches)
{ }
public MacroCacheRefresher(AppCaches appCaches, IJsonSerializer jsonSerializer)
: base(appCaches, jsonSerializer)
{
}
#region Define
@@ -57,7 +57,6 @@ namespace Umbraco.Web.Cache
base.Refresh(json);
}
#endregion
#region Json
@@ -75,21 +74,6 @@ namespace Umbraco.Web.Cache
public string Alias { get; }
}
private static JsonPayload[] Deserialize(string json)
{
return JsonConvert.DeserializeObject<JsonPayload[]>(json);
}
internal static string Serialize(params Macro[] macros)
{
return JsonConvert.SerializeObject(macros.Select(x => new JsonPayload(x.Id, x.Alias)).ToArray());
}
internal static string Serialize(params IMacro[] macros)
{
return JsonConvert.SerializeObject(macros.Select(x => new JsonPayload(x.Id, x.Alias)).ToArray());
}
#endregion
#region Helpers
@@ -2,14 +2,10 @@
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Repositories;
using System.Linq;
using System.Xml.Linq;
using Umbraco.Core.Persistence.Repositories.Implement;
using Umbraco.Core.Serialization;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Changes;
using Umbraco.Web.Composing;
using Umbraco.Web.PublishedCache;
namespace Umbraco.Web.Cache
@@ -17,13 +13,13 @@ namespace Umbraco.Web.Cache
public sealed class MediaCacheRefresher : PayloadCacheRefresherBase<MediaCacheRefresher, MediaCacheRefresher.JsonPayload>
{
private readonly IPublishedSnapshotService _publishedSnapshotService;
private readonly IdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
public MediaCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap)
public MediaCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IIdKeyMap idKeyMap)
: base(appCaches, serializer)
{
_publishedSnapshotService = publishedSnapshotService;
_idkMap = idkMap;
_idKeyMap = idKeyMap;
}
#region Define
@@ -48,14 +44,14 @@ namespace Umbraco.Web.Cache
if (anythingChanged)
{
Current.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;
@@ -1,4 +1,5 @@
using System;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Repositories;
@@ -9,12 +10,12 @@ namespace Umbraco.Web.Cache
{
public sealed class MemberCacheRefresher : TypedCacheRefresherBase<MemberCacheRefresher, IMember>
{
private readonly IdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
public MemberCacheRefresher(AppCaches appCaches, IdkMap idkMap)
public MemberCacheRefresher(AppCaches appCaches, IIdKeyMap idKeyMap)
: base(appCaches)
{
_idkMap = idkMap;
_idKeyMap = idKeyMap;
}
#region Define
@@ -57,7 +58,7 @@ namespace Umbraco.Web.Cache
private void ClearCache(int id)
{
_idkMap.ClearCache(id);
_idKeyMap.ClearCache(id);
AppCaches.ClearPartialViewCache();
var memberCache = AppCaches.IsolatedCaches.Get<IMember>();
@@ -1,16 +1,18 @@
using System;
using System.Linq;
using Newtonsoft.Json;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
using Umbraco.Core.Serialization;
namespace Umbraco.Web.Cache
{
public sealed class MemberGroupCacheRefresher : JsonCacheRefresherBase<MemberGroupCacheRefresher>
public sealed class MemberGroupCacheRefresher : JsonCacheRefresherBase<MemberGroupCacheRefresher, MemberGroupCacheRefresher.JsonPayload>
{
public MemberGroupCacheRefresher(AppCaches appCaches)
: base(appCaches)
{ }
public MemberGroupCacheRefresher(AppCaches appCaches, IJsonSerializer jsonSerializer)
: base(appCaches, jsonSerializer)
{
}
#region Define
@@ -68,15 +70,6 @@ namespace Umbraco.Web.Cache
public int Id { get; }
}
private JsonPayload[] Deserialize(string json)
{
return JsonConvert.DeserializeObject<JsonPayload[]>(json);
}
internal static string Serialize(params IMemberGroup[] groups)
{
return JsonConvert.SerializeObject(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 IdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
private readonly IContentTypeCommonRepository _contentTypeCommonRepository;
public TemplateCacheRefresher(AppCaches appCaches, IdkMap 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
@@ -38,7 +38,7 @@ namespace Umbraco.Web.Cache
var userGroupCache = AppCaches.IsolatedCaches.Get<IUserGroup>();
if (userGroupCache)
{
userGroupCache.Result.ClearByKey(UserGroupRepository.GetByAliasCacheKeyPrefix);
userGroupCache.Result.ClearByKey(CacheKeys.UserGroupGetByAliasCacheKeyPrefix);
}
//We'll need to clear all user cache too
@@ -59,7 +59,7 @@ namespace Umbraco.Web.Cache
if (userGroupCache)
{
userGroupCache.Result.Clear(RepositoryCacheKeys.GetKey<IUserGroup>(id));
userGroupCache.Result.ClearByKey(UserGroupRepository.GetByAliasCacheKeyPrefix);
userGroupCache.Result.ClearByKey(CacheKeys.UserGroupGetByAliasCacheKeyPrefix);
}
//we don't know what user's belong to this group without doing a look up so we'll need to just clear them all
@@ -0,0 +1,23 @@
using Umbraco.Core.Cache;
namespace Umbraco.Core
{
/// <summary>
/// Extension methods for the cache helper
/// </summary>
public static class CacheHelperExtensions
{
public const string PartialViewCacheKey = "Umbraco.Web.PartialViewCacheKey";
/// <summary>
/// Clears the cache for partial views
/// </summary>
/// <param name="appCaches"></param>
public static void ClearPartialViewCache(this AppCaches appCaches)
{
appCaches.RuntimeCache.ClearByKey(PartialViewCacheKey);
}
}
}
@@ -1,10 +1,9 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Serialization;
using Umbraco.Core.Services;
namespace Umbraco.Core.PropertyEditors.ValueConverters
@@ -13,10 +12,12 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
public class TagsValueConverter : PropertyValueConverterBase
{
private readonly IDataTypeService _dataTypeService;
private readonly IJsonSerializer _jsonSerializer;
public TagsValueConverter(IDataTypeService dataTypeService)
public TagsValueConverter(IDataTypeService dataTypeService, IJsonSerializer jsonSerializer)
{
_dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService));
_jsonSerializer = jsonSerializer ?? throw new ArgumentNullException(nameof(jsonSerializer));
}
public override bool IsConverter(IPublishedPropertyType propertyType)
@@ -35,8 +36,8 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
// if Json storage type deserialize and return as string array
if (JsonStorageType(propertyType.DataType.Id))
{
var jArray = JsonConvert.DeserializeObject<JArray>(source.ToString());
return jArray.ToObject<string[]>() ?? Array.Empty<string>();
var array = _jsonSerializer.Deserialize<string[]>(source.ToString());
return array ?? Array.Empty<string>();
}
// Otherwise assume CSV storage type and return as string array
@@ -0,0 +1,16 @@
using System;
using Umbraco.Core.Models;
namespace Umbraco.Core.Services
{
public interface IIdKeyMap
{
Attempt<int> GetIdForKey(Guid key, UmbracoObjectTypes umbracoObjectType);
Attempt<int> GetIdForUdi(Udi udi);
Attempt<Udi> GetUdiForId(int id, UmbracoObjectTypes umbracoObjectType);
Attempt<Guid> GetKeyForId(int id, UmbracoObjectTypes umbracoObjectType);
void ClearCache();
void ClearCache(int id);
void ClearCache(Guid key);
}
}
@@ -17,13 +17,6 @@ namespace Umbraco.Core.Sync
/// <param name="payload">The notification content.</param>
void PerformRefresh<TPayload>(ICacheRefresher refresher, TPayload[] payload);
/// <summary>
/// Notifies the distributed cache, for a specified <see cref="ICacheRefresher"/>.
/// </summary>
/// <param name="refresher">The ICacheRefresher.</param>
/// <param name="jsonPayload">The notification content.</param>
void PerformRefresh(ICacheRefresher refresher, string jsonPayload);
/// <summary>
/// Notifies the distributed cache of specified item invalidation, for a specified <see cref="ICacheRefresher"/>.
/// </summary>
@@ -24,7 +24,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions
composition.RegisterUnique<ServiceContext>();
// register the special idk map
composition.RegisterUnique<IdkMap>();
composition.RegisterUnique<IIdKeyMap, IdKeyMap>();
// register the services
composition.RegisterUnique<IPropertyValidationService, PropertyValidationService>();
@@ -32,10 +32,10 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
_permissionRepository = new PermissionRepository<IContent>(scopeAccessor, appCaches, logger);
}
public const string GetByAliasCacheKeyPrefix = "UserGroupRepository_GetByAlias_";
public static string GetByAliasCacheKey(string alias)
{
return GetByAliasCacheKeyPrefix + alias;
return CacheKeys.UserGroupGetByAliasCacheKeyPrefix + alias;
}
public IUserGroup Get(string alias)
@@ -7,7 +7,7 @@ using Umbraco.Core.Scoping;
namespace Umbraco.Core.Services
{
public class IdkMap
public class IdKeyMap : IIdKeyMap
{
private readonly IScopeProvider _scopeProvider;
private readonly ReaderWriterLockSlim _locker = new ReaderWriterLockSlim();
@@ -15,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 IdkMap _idkMap;
private readonly IIdKeyMap _idKeyMap;
public EntityService(IScopeProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IdkMap 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 />
@@ -45,7 +45,7 @@ namespace Umbraco.Web
var attribute = member.GetCustomAttribute<ImplementPropertyTypeAttribute>();
if (attribute == null)
throw new InvalidOperationException("Property is not marked with ImplementPropertyType attribute.");
return attribute.Alias;
}
}
@@ -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,10 +3,12 @@ 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;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Serialization;
using Umbraco.Core.Services;
using Umbraco.Tests.Testing;
using Umbraco.Tests.Testing.Objects.Accessors;
@@ -150,7 +150,6 @@ namespace Umbraco.Tests.PublishedContent
runtime,
serviceContext,
contentTypeFactory,
null,
_snapshotAccessor,
_variationAccesor,
Mock.Of<IProfilingLogger>(),
@@ -192,7 +192,6 @@ namespace Umbraco.Tests.PublishedContent
runtime,
serviceContext,
contentTypeFactory,
null,
new TestPublishedSnapshotAccessor(),
_variationAccesor,
Mock.Of<IProfilingLogger>(),
@@ -92,7 +92,6 @@ namespace Umbraco.Tests.Scoping
runtimeStateMock.Object,
ServiceContext,
contentTypeFactory,
null,
publishedSnapshotAccessor,
Mock.Of<IVariationContextAccessor>(),
ProfilingLogger,
@@ -65,7 +65,6 @@ namespace Umbraco.Tests.Services
runtimeStateMock.Object,
ServiceContext,
contentTypeFactory,
null,
publishedSnapshotAccessor,
Mock.Of<IVariationContextAccessor>(),
ProfilingLogger,
+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>()));
@@ -111,6 +111,7 @@ namespace Umbraco.Tests.Testing
#region Accessors
protected ILogger Logger => Factory.GetInstance<ILogger>();
protected IJsonSerializer JsonNetSerializer { get; } = new JsonNetSerializer();
protected IIOHelper IOHelper { get; private set; }
protected IDataTypeService DataTypeService => Factory.GetInstance<IDataTypeService>();
-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,8 +4,10 @@ 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;
namespace Umbraco.Web.Cache
{
@@ -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;
@@ -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);
}
@@ -1,5 +1,8 @@
using System.Linq;
using NPoco.Expressions;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
using Umbraco.Core.Serialization;
using Umbraco.Core.Services.Changes;
namespace Umbraco.Web.Cache
@@ -192,13 +195,15 @@ namespace Umbraco.Web.Cache
public static void RefreshMacroCache(this DistributedCache dc, IMacro macro)
{
if (macro == null) return;
dc.RefreshByJson(MacroCacheRefresher.UniqueId, MacroCacheRefresher.Serialize(macro));
var payloads = new[] { new MacroCacheRefresher.JsonPayload(macro.Id, macro.Alias) };
dc.RefreshByPayload(MacroCacheRefresher.UniqueId, payloads);
}
public static void RemoveMacroCache(this DistributedCache dc, IMacro macro)
{
if (macro == null) return;
dc.RefreshByJson(MacroCacheRefresher.UniqueId, MacroCacheRefresher.Serialize(macro));
var payloads = new[] { new MacroCacheRefresher.JsonPayload(macro.Id, macro.Alias) };
dc.RefreshByPayload(MacroCacheRefresher.UniqueId, payloads);
}
#endregion
@@ -298,5 +303,7 @@ namespace Umbraco.Web.Cache
}
#endregion
}
}
+1 -12
View File
@@ -12,9 +12,6 @@ namespace Umbraco.Web
/// </summary>
public static class CacheHelperExtensions
{
public const string PartialViewCacheKey = "Umbraco.Web.PartialViewCacheKey";
/// <summary>
/// Outputs and caches a partial view in MVC
/// </summary>
@@ -43,18 +40,10 @@ namespace Umbraco.Web
}
return appCaches.RuntimeCache.GetCacheItem<IHtmlString>(
PartialViewCacheKey + cacheKey,
Core.CacheHelperExtensions.PartialViewCacheKey + cacheKey,
() => htmlHelper.Partial(partialViewName, model, viewData),
timeout: new TimeSpan(0, 0, 0, cachedSeconds));
}
/// <summary>
/// Clears the cache for partial views
/// </summary>
/// <param name="appCaches"></param>
public static void ClearPartialViewCache(this AppCaches appCaches)
{
appCaches.RuntimeCache.ClearByKey(PartialViewCacheKey);
}
}
}
@@ -1,5 +1,8 @@
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Models;
using Umbraco.Core.Scoping;
using Umbraco.Core.Services;
using Umbraco.Web.PublishedCache.NuCache.DataSource;
namespace Umbraco.Web.PublishedCache.NuCache
@@ -18,6 +21,20 @@ namespace Umbraco.Web.PublishedCache.NuCache
composition.Register(factory => new PublishedSnapshotServiceOptions());
composition.SetPublishedSnapshotService<PublishedSnapshotService>();
// replace this service since we want to improve the content/media
// mapping lookups if we are using nucache.
composition.RegisterUnique<IIdKeyMap>(factory =>
{
var idkSvc = new IdKeyMap(factory.GetInstance<IScopeProvider>());
var publishedSnapshotService = factory.GetInstance<IPublishedSnapshotService>() as PublishedSnapshotService;
if (publishedSnapshotService != null)
{
idkSvc.SetMapper(UmbracoObjectTypes.Document, id => publishedSnapshotService.GetDocumentUid(id), uid => publishedSnapshotService.GetDocumentId(uid));
idkSvc.SetMapper(UmbracoObjectTypes.Media, id => publishedSnapshotService.GetMediaUid(id), uid => publishedSnapshotService.GetMediaId(uid));
}
return idkSvc;
});
// add the NuCache health check (hidden from type finder)
// TODO: no NuCache health check yet
//composition.HealthChecks().Add<NuCacheIntegrityHealthCheck>();
@@ -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, IdkMap idkMap,
ServiceContext serviceContext, IPublishedContentTypeFactory publishedContentTypeFactory,
IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IProfilingLogger logger, IScopeProvider scopeProvider,
IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository,
IDefaultCultureAccessor defaultCultureAccessor,
@@ -156,17 +156,22 @@ namespace Umbraco.Web.PublishedCache.NuCache
LoadCachesOnStartup();
}
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)
{
idkMap.SetMapper(UmbracoObjectTypes.Document, id => GetUid(_contentStore, id), uid => GetId(_contentStore, uid));
idkMap.SetMapper(UmbracoObjectTypes.Media, id => GetUid(_mediaStore, id), uid => GetId(_mediaStore, uid));
}
}
#region Id <-> Key methods
// NOTE: These aren't used within this object but are made available internally to improve the IdKey lookup performance
// when nucache is enabled.
internal int GetDocumentId(Guid udi) => GetId(_contentStore, udi);
internal int GetMediaId(Guid udi) => GetId(_mediaStore, udi);
internal Guid GetDocumentUid(int id) => GetUid(_contentStore, id);
internal Guid GetMediaUid(int id) => GetUid(_mediaStore, id);
private int GetId(ContentStore store, Guid uid) => store.LiveSnapshot.Get(uid)?.Id ?? default;
private Guid GetUid(ContentStore store, int id) => store.LiveSnapshot.Get(id)?.Uid ?? default;
#endregion
/// <summary>
/// Install phase of <see cref="IMainDom"/>
/// </summary>
@@ -145,7 +145,7 @@ namespace Umbraco.Web.Runtime
composition.RegisterUnique<IEventMessagesFactory, DefaultEventMessagesFactory>();
composition.RegisterUnique<IEventMessagesAccessor, HybridEventMessagesAccessor>();
composition.RegisterUnique<ITreeService, TreeService>();
composition.RegisterUnique<ISectionService, SectionService>();
composition.RegisterUnique<ISectionService, SectionService>();
composition.RegisterUnique<IDashboardService, DashboardService>();
-33
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>
@@ -137,9 +133,6 @@
<Compile Include="Cache\DistributedCacheBinder.cs" />
<Compile Include="Cache\DistributedCacheBinderComposer.cs" />
<Compile Include="Cache\DistributedCacheBinder_Handlers.cs" />
<Compile Include="Cache\ContentCacheRefresher.cs" />
<Compile Include="Cache\IDistributedCacheBinder.cs" />
<Compile Include="Cache\UserGroupCacheRefresher.cs" />
<Compile Include="Cache\WebCachingAppCache.cs" />
<Compile Include="Compose\AuditEventsComponent.cs" />
<Compile Include="Compose\AuditEventsComposer.cs" />
@@ -351,7 +344,6 @@
<Compile Include="HttpContextUmbracoContextAccessor.cs" />
<Compile Include="HybridEventMessagesAccessor.cs" />
<Compile Include="IHttpContextAccessor.cs" />
<Compile Include="Cache\RelationTypeCacheRefresher.cs" />
<Compile Include="Composing\CompositionExtensions\WebMappingProfiles.cs" />
<Compile Include="Editors\BackOfficeNotificationsController.cs" />
<Compile Include="Install\InstallStepCollection.cs" />
@@ -408,8 +400,6 @@
<Compile Include="PropertyEditors\ValueConverters\MediaPickerValueConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\MemberPickerValueConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\MultiNodeTreePickerValueConverter.cs" />
<Compile Include="PublishedCache\IPublishedSnapshot.cs" />
<Compile Include="PublishedCache\IDefaultCultureAccessor.cs" />
<Compile Include="PublishedCache\NuCache\DataSource\BTree.ContentDataSerializer.cs" />
<Compile Include="PublishedCache\NuCache\DataSource\BTree.ContentNodeKitSerializer.cs" />
<Compile Include="PublishedCache\NuCache\DataSource\BTree.DictionaryOfCultureVariationSerializer.cs" />
@@ -425,10 +415,6 @@
<Compile Include="PublishedCache\PublishedElementPropertyBase.cs" />
<Compile Include="PropertyEditors\ValueConverters\ContentPickerValueConverter.cs" />
<Compile Include="PublishedCache\PublishedSnapshotServiceBase.cs" />
<Compile Include="PublishedCache\IDomainCache.cs" />
<Compile Include="PublishedCache\IPublishedSnapshotAccessor.cs" />
<Compile Include="PublishedCache\IPublishedSnapshotService.cs" />
<Compile Include="PublishedCache\IPublishedMemberCache.cs" />
<Compile Include="PublishedCache\NuCache\CacheKeys.cs" />
<Compile Include="PublishedCache\NuCache\ContentCache.cs" />
<Compile Include="PublishedCache\NuCache\ContentNode.cs" />
@@ -462,7 +448,6 @@
<Compile Include="Routing\ContentFinderByUrlAndTemplate.cs" />
<Compile Include="Routing\ContentFinderCollection.cs" />
<Compile Include="Routing\ContentFinderCollectionBuilder.cs" />
<Compile Include="Routing\Domain.cs" />
<Compile Include="Routing\IContentLastChanceFinder.cs" />
<Compile Include="Routing\UrlProviderCollection.cs" />
<Compile Include="Routing\UrlProviderCollectionBuilder.cs" />
@@ -547,22 +532,7 @@
<Compile Include="Scheduling\BackgroundTaskRunner.cs" />
<Compile Include="BatchedDatabaseServerMessenger.cs" />
<Compile Include="CacheHelperExtensions.cs" />
<Compile Include="Cache\ApplicationCacheRefresher.cs" />
<Compile Include="Cache\ContentTypeCacheRefresher.cs" />
<Compile Include="Cache\DataTypeCacheRefresher.cs" />
<Compile Include="Cache\DictionaryCacheRefresher.cs" />
<Compile Include="Cache\DistributedCache.cs" />
<Compile Include="Cache\DistributedCacheExtensions.cs" />
<Compile Include="Cache\DistributedCacheBinderComponent.cs" />
<Compile Include="Cache\DomainCacheRefresher.cs" />
<Compile Include="Cache\LanguageCacheRefresher.cs" />
<Compile Include="Cache\MacroCacheRefresher.cs" />
<Compile Include="Cache\MediaCacheRefresher.cs" />
<Compile Include="Cache\MemberCacheRefresher.cs" />
<Compile Include="Cache\MemberGroupCacheRefresher.cs" />
<Compile Include="Cache\PublicAccessCacheRefresher.cs" />
<Compile Include="Cache\TemplateCacheRefresher.cs" />
<Compile Include="Cache\UserCacheRefresher.cs" />
<Compile Include="Editors\AuthenticationController.cs" />
<Compile Include="Controllers\UmbProfileController.cs" />
<Compile Include="Editors\ContentController.cs" />
@@ -785,9 +755,6 @@
<Compile Include="Mvc\UmbracoControllerFactory.cs" />
<Compile Include="Mvc\UmbracoMvcHandler.cs" />
<Compile Include="Mvc\UmbracoViewPageOfTModel.cs" />
<Compile Include="PublishedCache\IPublishedCache.cs" />
<Compile Include="PublishedCache\IPublishedContentCache.cs" />
<Compile Include="PublishedCache\IPublishedMediaCache.cs" />
<Compile Include="PublishedContentExtensions.cs" />
<Compile Include="ExamineExtensions.cs" />
<Compile Include="FormlessPage.cs">