diff --git a/src/Umbraco.Web/Cache/ApplicationCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/ApplicationCacheRefresher.cs similarity index 100% rename from src/Umbraco.Web/Cache/ApplicationCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/ApplicationCacheRefresher.cs diff --git a/src/Umbraco.Abstractions/Cache/CacheKeys.cs b/src/Umbraco.Abstractions/Cache/CacheKeys.cs index b8ee0e97c4..ec57d633b9 100644 --- a/src/Umbraco.Abstractions/Cache/CacheKeys.cs +++ b/src/Umbraco.Abstractions/Cache/CacheKeys.cs @@ -12,5 +12,7 @@ public const string MacroContentCacheKey = "macroContent_"; // used in MacroRenderers public const string MacroFromAliasCacheKey = "macroFromAlias_"; + + public const string UserGroupGetByAliasCacheKeyPrefix = "UserGroupRepository_GetByAlias_"; } } diff --git a/src/Umbraco.Web/Cache/ContentCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/ContentCacheRefresher.cs similarity index 96% rename from src/Umbraco.Web/Cache/ContentCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/ContentCacheRefresher.cs index 5c997efeaf..1be0eba3c2 100644 --- a/src/Umbraco.Web/Cache/ContentCacheRefresher.cs +++ b/src/Umbraco.Abstractions/Cache/ContentCacheRefresher.cs @@ -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,10 +15,10 @@ namespace Umbraco.Web.Cache public sealed class ContentCacheRefresher : PayloadCacheRefresherBase { private readonly IPublishedSnapshotService _publishedSnapshotService; - private readonly IdkMap _idkMap; + private readonly IIdkMap _idkMap; private readonly IDomainService _domainService; - public ContentCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap, IDomainService domainService) + public ContentCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IIdkMap idkMap, IDomainService domainService) : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; @@ -141,7 +137,6 @@ namespace Umbraco.Web.Cache public class JsonPayload { - [JsonConstructor] public JsonPayload(int id, Guid? key, TreeChangeTypes changeTypes) { Id = id; diff --git a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/ContentTypeCacheRefresher.cs similarity index 96% rename from src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/ContentTypeCacheRefresher.cs index 655baf18bf..3612c064e4 100644 --- a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs +++ b/src/Umbraco.Abstractions/Cache/ContentTypeCacheRefresher.cs @@ -17,9 +17,9 @@ namespace Umbraco.Web.Cache private readonly IPublishedSnapshotService _publishedSnapshotService; private readonly IPublishedModelFactory _publishedModelFactory; private readonly IContentTypeCommonRepository _contentTypeCommonRepository; - private readonly IdkMap _idkMap; + private readonly IIdkMap _idkMap; - public ContentTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) + public ContentTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IIdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; diff --git a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/DataTypeCacheRefresher.cs similarity index 96% rename from src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/DataTypeCacheRefresher.cs index 3c83ff3027..44fd755dda 100644 --- a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs +++ b/src/Umbraco.Abstractions/Cache/DataTypeCacheRefresher.cs @@ -15,9 +15,9 @@ namespace Umbraco.Web.Cache { private readonly IPublishedSnapshotService _publishedSnapshotService; private readonly IPublishedModelFactory _publishedModelFactory; - private readonly IdkMap _idkMap; + private readonly IIdkMap _idkMap; - public DataTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap) + public DataTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IIdkMap idkMap) : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; diff --git a/src/Umbraco.Web/Cache/DictionaryCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/DictionaryCacheRefresher.cs similarity index 100% rename from src/Umbraco.Web/Cache/DictionaryCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/DictionaryCacheRefresher.cs diff --git a/src/Umbraco.Web/Cache/DistributedCache.cs b/src/Umbraco.Abstractions/Cache/DistributedCache.cs similarity index 99% rename from src/Umbraco.Web/Cache/DistributedCache.cs rename to src/Umbraco.Abstractions/Cache/DistributedCache.cs index d77c3c056b..7f628d819f 100644 --- a/src/Umbraco.Web/Cache/DistributedCache.cs +++ b/src/Umbraco.Abstractions/Cache/DistributedCache.cs @@ -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 { diff --git a/src/Umbraco.Web/Cache/DistributedCacheBinderComponent.cs b/src/Umbraco.Abstractions/Cache/DistributedCacheBinderComponent.cs similarity index 100% rename from src/Umbraco.Web/Cache/DistributedCacheBinderComponent.cs rename to src/Umbraco.Abstractions/Cache/DistributedCacheBinderComponent.cs diff --git a/src/Umbraco.Web/Cache/DomainCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/DomainCacheRefresher.cs similarity index 100% rename from src/Umbraco.Web/Cache/DomainCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/DomainCacheRefresher.cs diff --git a/src/Umbraco.Web/Cache/IDistributedCacheBinder.cs b/src/Umbraco.Abstractions/Cache/IDistributedCacheBinder.cs similarity index 96% rename from src/Umbraco.Web/Cache/IDistributedCacheBinder.cs rename to src/Umbraco.Abstractions/Cache/IDistributedCacheBinder.cs index e4237fea94..cb83799f85 100644 --- a/src/Umbraco.Web/Cache/IDistributedCacheBinder.cs +++ b/src/Umbraco.Abstractions/Cache/IDistributedCacheBinder.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using Umbraco.Core.Events; -using Umbraco.Core.Services.Implement; namespace Umbraco.Web.Cache { diff --git a/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/LanguageCacheRefresher.cs similarity index 100% rename from src/Umbraco.Web/Cache/LanguageCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/LanguageCacheRefresher.cs diff --git a/src/Umbraco.Web/Cache/MacroCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/MacroCacheRefresher.cs similarity index 77% rename from src/Umbraco.Web/Cache/MacroCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/MacroCacheRefresher.cs index 24479b8415..8cd72a1852 100644 --- a/src/Umbraco.Web/Cache/MacroCacheRefresher.cs +++ b/src/Umbraco.Abstractions/Cache/MacroCacheRefresher.cs @@ -1,19 +1,21 @@ 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 { - public MacroCacheRefresher(AppCaches appCaches) + private readonly IJsonSerializer _jsonSerializer; + + public MacroCacheRefresher(AppCaches appCaches, IJsonSerializer jsonSerializer) : base(appCaches) - { } + { + _jsonSerializer = jsonSerializer; + } #region Define @@ -41,7 +43,7 @@ namespace Umbraco.Web.Cache public override void Refresh(string json) { - var payloads = Deserialize(json); + var payloads = Deserialize(_jsonSerializer, json); foreach (var payload in payloads) { @@ -75,19 +77,15 @@ namespace Umbraco.Web.Cache public string Alias { get; } } - private static JsonPayload[] Deserialize(string json) + public static JsonPayload[] Deserialize(IJsonSerializer jsonSerializer, string json) { - return JsonConvert.DeserializeObject(json); + return jsonSerializer.Deserialize(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) + public static string Serialize( IJsonSerializer jsonSerializer, params IMacro[] macros) { - return JsonConvert.SerializeObject(macros.Select(x => new JsonPayload(x.Id, x.Alias)).ToArray()); + return jsonSerializer.Serialize(macros.Select(x => new JsonPayload(x.Id, x.Alias)).ToArray()); } #endregion diff --git a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/MediaCacheRefresher.cs similarity index 93% rename from src/Umbraco.Web/Cache/MediaCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/MediaCacheRefresher.cs index 8da643c279..bb6d083a06 100644 --- a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs +++ b/src/Umbraco.Abstractions/Cache/MediaCacheRefresher.cs @@ -2,26 +2,24 @@ 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 { public sealed class MediaCacheRefresher : PayloadCacheRefresherBase { + private readonly AppCaches _appCaches; private readonly IPublishedSnapshotService _publishedSnapshotService; - private readonly IdkMap _idkMap; + private readonly IIdkMap _idkMap; - public MediaCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap) + public MediaCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IIdkMap idkMap) : base(appCaches, serializer) { + _appCaches = appCaches; _publishedSnapshotService = publishedSnapshotService; _idkMap = idkMap; } @@ -48,7 +46,7 @@ namespace Umbraco.Web.Cache if (anythingChanged) { - Current.AppCaches.ClearPartialViewCache(); + _appCaches.ClearPartialViewCache(); var mediaCache = AppCaches.IsolatedCaches.Get(); diff --git a/src/Umbraco.Web/Cache/MemberCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/MemberCacheRefresher.cs similarity index 87% rename from src/Umbraco.Web/Cache/MemberCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/MemberCacheRefresher.cs index 1565b1c849..a2c1faca69 100644 --- a/src/Umbraco.Web/Cache/MemberCacheRefresher.cs +++ b/src/Umbraco.Abstractions/Cache/MemberCacheRefresher.cs @@ -1,4 +1,5 @@ using System; +using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories; @@ -9,11 +10,13 @@ namespace Umbraco.Web.Cache { public sealed class MemberCacheRefresher : TypedCacheRefresherBase { - private readonly IdkMap _idkMap; + private readonly AppCaches _appCaches; + private readonly IIdkMap _idkMap; - public MemberCacheRefresher(AppCaches appCaches, IdkMap idkMap) + public MemberCacheRefresher(AppCaches appCaches, IIdkMap idkMap) : base(appCaches) { + _appCaches = appCaches; _idkMap = idkMap; } @@ -58,7 +61,7 @@ namespace Umbraco.Web.Cache private void ClearCache(int id) { _idkMap.ClearCache(id); - AppCaches.ClearPartialViewCache(); + _appCaches.ClearPartialViewCache(); var memberCache = AppCaches.IsolatedCaches.Get(); if (memberCache) diff --git a/src/Umbraco.Web/Cache/MemberGroupCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/MemberGroupCacheRefresher.cs similarity index 78% rename from src/Umbraco.Web/Cache/MemberGroupCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/MemberGroupCacheRefresher.cs index 3e195cec5e..b1dc305e21 100644 --- a/src/Umbraco.Web/Cache/MemberGroupCacheRefresher.cs +++ b/src/Umbraco.Abstractions/Cache/MemberGroupCacheRefresher.cs @@ -1,16 +1,20 @@ 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 { - public MemberGroupCacheRefresher(AppCaches appCaches) + private readonly IJsonSerializer _jsonSerializer; + + public MemberGroupCacheRefresher(AppCaches appCaches, IJsonSerializer jsonSerializer) : base(appCaches) - { } + { + _jsonSerializer = jsonSerializer; + } #region Define @@ -70,12 +74,12 @@ namespace Umbraco.Web.Cache private JsonPayload[] Deserialize(string json) { - return JsonConvert.DeserializeObject(json); + return _jsonSerializer.Deserialize(json); } - internal static string Serialize(params IMemberGroup[] groups) + private string Serialize(params IMemberGroup[] groups) { - return JsonConvert.SerializeObject(groups.Select(x => new JsonPayload(x.Id, x.Name)).ToArray()); + return _jsonSerializer.Serialize(groups.Select(x => new JsonPayload(x.Id, x.Name)).ToArray()); } #endregion diff --git a/src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/PublicAccessCacheRefresher.cs similarity index 100% rename from src/Umbraco.Web/Cache/PublicAccessCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/PublicAccessCacheRefresher.cs diff --git a/src/Umbraco.Web/Cache/RelationTypeCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/RelationTypeCacheRefresher.cs similarity index 100% rename from src/Umbraco.Web/Cache/RelationTypeCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/RelationTypeCacheRefresher.cs diff --git a/src/Umbraco.Web/Cache/TemplateCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/TemplateCacheRefresher.cs similarity index 92% rename from src/Umbraco.Web/Cache/TemplateCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/TemplateCacheRefresher.cs index 2c93a6f754..99bb1f2175 100644 --- a/src/Umbraco.Web/Cache/TemplateCacheRefresher.cs +++ b/src/Umbraco.Abstractions/Cache/TemplateCacheRefresher.cs @@ -8,10 +8,10 @@ namespace Umbraco.Web.Cache { public sealed class TemplateCacheRefresher : CacheRefresherBase { - private readonly IdkMap _idkMap; + private readonly IIdkMap _idkMap; private readonly IContentTypeCommonRepository _contentTypeCommonRepository; - public TemplateCacheRefresher(AppCaches appCaches, IdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) + public TemplateCacheRefresher(AppCaches appCaches, IIdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) : base(appCaches) { _idkMap = idkMap; diff --git a/src/Umbraco.Web/Cache/UserCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/UserCacheRefresher.cs similarity index 100% rename from src/Umbraco.Web/Cache/UserCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/UserCacheRefresher.cs diff --git a/src/Umbraco.Web/Cache/UserGroupCacheRefresher.cs b/src/Umbraco.Abstractions/Cache/UserGroupCacheRefresher.cs similarity index 91% rename from src/Umbraco.Web/Cache/UserGroupCacheRefresher.cs rename to src/Umbraco.Abstractions/Cache/UserGroupCacheRefresher.cs index cfdf8f3669..3fd34abfcd 100644 --- a/src/Umbraco.Web/Cache/UserGroupCacheRefresher.cs +++ b/src/Umbraco.Abstractions/Cache/UserGroupCacheRefresher.cs @@ -38,7 +38,7 @@ namespace Umbraco.Web.Cache var userGroupCache = AppCaches.IsolatedCaches.Get(); 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(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 diff --git a/src/Umbraco.Abstractions/CacheHelperExtensions.cs b/src/Umbraco.Abstractions/CacheHelperExtensions.cs new file mode 100644 index 0000000000..2b01ae1028 --- /dev/null +++ b/src/Umbraco.Abstractions/CacheHelperExtensions.cs @@ -0,0 +1,23 @@ +using Umbraco.Core.Cache; + +namespace Umbraco.Core +{ + + /// + /// Extension methods for the cache helper + /// + public static class CacheHelperExtensions + { + + public const string PartialViewCacheKey = "Umbraco.Web.PartialViewCacheKey"; + + /// + /// Clears the cache for partial views + /// + /// + public static void ClearPartialViewCache(this AppCaches appCaches) + { + appCaches.RuntimeCache.ClearByKey(PartialViewCacheKey); + } + } +} diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/IContentTypeCommonRepository.cs b/src/Umbraco.Abstractions/Persistence/Repositories/IContentTypeCommonRepository.cs similarity index 100% rename from src/Umbraco.Infrastructure/Persistence/Repositories/IContentTypeCommonRepository.cs rename to src/Umbraco.Abstractions/Persistence/Repositories/IContentTypeCommonRepository.cs diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RepositoryCacheKeys.cs b/src/Umbraco.Abstractions/Persistence/Repositories/RepositoryCacheKeys.cs similarity index 100% rename from src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RepositoryCacheKeys.cs rename to src/Umbraco.Abstractions/Persistence/Repositories/RepositoryCacheKeys.cs diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/SliderValueConverter.cs b/src/Umbraco.Abstractions/PropertyEditors/ValueConverters/SliderValueConverter.cs similarity index 100% rename from src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/SliderValueConverter.cs rename to src/Umbraco.Abstractions/PropertyEditors/ValueConverters/SliderValueConverter.cs diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/TagsValueConverter.cs b/src/Umbraco.Abstractions/PropertyEditors/ValueConverters/TagsValueConverter.cs similarity index 88% rename from src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/TagsValueConverter.cs rename to src/Umbraco.Abstractions/PropertyEditors/ValueConverters/TagsValueConverter.cs index 0b347b8500..edacd500df 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/TagsValueConverter.cs +++ b/src/Umbraco.Abstractions/PropertyEditors/ValueConverters/TagsValueConverter.cs @@ -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(source.ToString()); - return jArray.ToObject() ?? Array.Empty(); + var array = _jsonSerializer.Deserialize(source.ToString()); + return array ?? Array.Empty(); } // Otherwise assume CSV storage type and return as string array diff --git a/src/Umbraco.Web/PublishedCache/IDefaultCultureAccessor.cs b/src/Umbraco.Abstractions/PublishedCache/IDefaultCultureAccessor.cs similarity index 100% rename from src/Umbraco.Web/PublishedCache/IDefaultCultureAccessor.cs rename to src/Umbraco.Abstractions/PublishedCache/IDefaultCultureAccessor.cs diff --git a/src/Umbraco.Web/PublishedCache/IDomainCache.cs b/src/Umbraco.Abstractions/PublishedCache/IDomainCache.cs similarity index 100% rename from src/Umbraco.Web/PublishedCache/IDomainCache.cs rename to src/Umbraco.Abstractions/PublishedCache/IDomainCache.cs diff --git a/src/Umbraco.Web/PublishedCache/IPublishedCache.cs b/src/Umbraco.Abstractions/PublishedCache/IPublishedCache.cs similarity index 100% rename from src/Umbraco.Web/PublishedCache/IPublishedCache.cs rename to src/Umbraco.Abstractions/PublishedCache/IPublishedCache.cs diff --git a/src/Umbraco.Web/PublishedCache/IPublishedContentCache.cs b/src/Umbraco.Abstractions/PublishedCache/IPublishedContentCache.cs similarity index 100% rename from src/Umbraco.Web/PublishedCache/IPublishedContentCache.cs rename to src/Umbraco.Abstractions/PublishedCache/IPublishedContentCache.cs diff --git a/src/Umbraco.Web/PublishedCache/IPublishedMediaCache.cs b/src/Umbraco.Abstractions/PublishedCache/IPublishedMediaCache.cs similarity index 100% rename from src/Umbraco.Web/PublishedCache/IPublishedMediaCache.cs rename to src/Umbraco.Abstractions/PublishedCache/IPublishedMediaCache.cs diff --git a/src/Umbraco.Web/PublishedCache/IPublishedMemberCache.cs b/src/Umbraco.Abstractions/PublishedCache/IPublishedMemberCache.cs similarity index 100% rename from src/Umbraco.Web/PublishedCache/IPublishedMemberCache.cs rename to src/Umbraco.Abstractions/PublishedCache/IPublishedMemberCache.cs diff --git a/src/Umbraco.Web/PublishedCache/IPublishedSnapshot.cs b/src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshot.cs similarity index 100% rename from src/Umbraco.Web/PublishedCache/IPublishedSnapshot.cs rename to src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshot.cs diff --git a/src/Umbraco.Web/PublishedCache/IPublishedSnapshotAccessor.cs b/src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotAccessor.cs similarity index 100% rename from src/Umbraco.Web/PublishedCache/IPublishedSnapshotAccessor.cs rename to src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotAccessor.cs diff --git a/src/Umbraco.Web/PublishedCache/IPublishedSnapshotService.cs b/src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotService.cs similarity index 100% rename from src/Umbraco.Web/PublishedCache/IPublishedSnapshotService.cs rename to src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotService.cs diff --git a/src/Umbraco.Web/Routing/Domain.cs b/src/Umbraco.Abstractions/Routing/Domain.cs similarity index 100% rename from src/Umbraco.Web/Routing/Domain.cs rename to src/Umbraco.Abstractions/Routing/Domain.cs diff --git a/src/Umbraco.Abstractions/Services/IIdkMap.cs b/src/Umbraco.Abstractions/Services/IIdkMap.cs new file mode 100644 index 0000000000..213d614951 --- /dev/null +++ b/src/Umbraco.Abstractions/Services/IIdkMap.cs @@ -0,0 +1,17 @@ +using System; +using Umbraco.Core.Models; + +namespace Umbraco.Core.Services +{ + public interface IIdkMap + { + void SetMapper(UmbracoObjectTypes umbracoObjectType, Func id2key, Func key2id); + Attempt GetIdForKey(Guid key, UmbracoObjectTypes umbracoObjectType); + Attempt GetIdForUdi(Udi udi); + Attempt GetUdiForId(int id, UmbracoObjectTypes umbracoObjectType); + Attempt GetKeyForId(int id, UmbracoObjectTypes umbracoObjectType); + void ClearCache(); + void ClearCache(int id); + void ClearCache(Guid key); + } +} \ No newline at end of file diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs index f7c7c91c08..3b5f3ca820 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs @@ -24,7 +24,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions composition.RegisterUnique(); // register the special idk map - composition.RegisterUnique(); + composition.RegisterUnique(); // register the services composition.RegisterUnique(); diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserGroupRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserGroupRepository.cs index 1f0ab0cbe7..07cfbb05a8 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserGroupRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserGroupRepository.cs @@ -32,10 +32,10 @@ namespace Umbraco.Core.Persistence.Repositories.Implement _permissionRepository = new PermissionRepository(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) diff --git a/src/Umbraco.Infrastructure/Services/IdkMap.cs b/src/Umbraco.Infrastructure/Services/IdkMap.cs index f7790ba76b..a3526d020d 100644 --- a/src/Umbraco.Infrastructure/Services/IdkMap.cs +++ b/src/Umbraco.Infrastructure/Services/IdkMap.cs @@ -7,7 +7,8 @@ using Umbraco.Core.Scoping; namespace Umbraco.Core.Services { - public class IdkMap + //Todo rename to IdKeyMap + public class IdkMap : IIdkMap { private readonly IScopeProvider _scopeProvider; private readonly ReaderWriterLockSlim _locker = new ReaderWriterLockSlim(); diff --git a/src/Umbraco.Infrastructure/Services/Implement/EntityService.cs b/src/Umbraco.Infrastructure/Services/Implement/EntityService.cs index 04e2624592..459868b152 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/EntityService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/EntityService.cs @@ -19,9 +19,9 @@ namespace Umbraco.Core.Services.Implement private readonly IEntityRepository _entityRepository; private readonly Dictionary _objectTypes; private IQuery _queryRootEntity; - private readonly IdkMap _idkMap; + private readonly IIdkMap _idkMap; - public EntityService(IScopeProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IdkMap idkMap, IEntityRepository entityRepository) + public EntityService(IScopeProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IIdkMap idkMap, IEntityRepository entityRepository) : base(provider, logger, eventMessagesFactory) { _idkMap = idkMap; diff --git a/src/Umbraco.ModelsBuilder.Embedded/PublishedElementExtensions.cs b/src/Umbraco.ModelsBuilder.Embedded/PublishedElementExtensions.cs index 29429ba74f..e91b60dba0 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/PublishedElementExtensions.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/PublishedElementExtensions.cs @@ -45,7 +45,7 @@ namespace Umbraco.Web var attribute = member.GetCustomAttribute(); if (attribute == null) throw new InvalidOperationException("Property is not marked with ImplementPropertyType attribute."); - + return attribute.Alias; } } diff --git a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs index 880bee4904..be34abe285 100644 --- a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs @@ -7,6 +7,7 @@ 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; @@ -164,7 +165,7 @@ namespace Umbraco.Tests.Cache IOHelper); // just assert it does not throw - var refreshers = new DistributedCacheBinder(null, umbracoContextFactory, null); + var refreshers = new DistributedCacheBinder(null, umbracoContextFactory, null, JsonNetSerializer); refreshers.HandleEvents(definitions); } } diff --git a/src/Umbraco.Tests/Integration/ContentEventsTests.cs b/src/Umbraco.Tests/Integration/ContentEventsTests.cs index 575215c41f..9e1b7c2654 100644 --- a/src/Umbraco.Tests/Integration/ContentEventsTests.cs +++ b/src/Umbraco.Tests/Integration/ContentEventsTests.cs @@ -33,7 +33,7 @@ namespace Umbraco.Tests.Integration { base.SetUp(); - _h1 = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of(), Mock.Of()); + _h1 = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of(), Mock.Of(), JsonNetSerializer); _h1.BindEvents(true); _events = new List(); diff --git a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs index 3ecc16b8a9..db39d12a79 100644 --- a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs @@ -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(), Mock.Of()); + _distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of(), Mock.Of(), JsonNetSerializer); _distributedCacheBinder.BindEvents(true); // create document type, document diff --git a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs index 7a0b2082b3..ae81c3ea0f 100644 --- a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs @@ -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(), Mock.Of()); + _distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of(), Mock.Of(), JsonNetSerializer); _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(), Mock.Of()); + _distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of(), Mock.Of(), JsonNetSerializer); _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(), Mock.Of()); + _distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of(), Mock.Of(), JsonNetSerializer); _distributedCacheBinder.BindEvents(true); Assert.IsNull(scopeProvider.AmbientScope); diff --git a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs index 24b41d3322..4458a55fdc 100644 --- a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs @@ -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(), Mock.Of()); + _distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of(), Mock.Of(), JsonNetSerializer); _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(), Mock.Of()); + _distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of(), Mock.Of(), JsonNetSerializer); _distributedCacheBinder.BindEvents(true); // check xml in context = "before" diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 34846a8123..26f1bda576 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -108,6 +108,7 @@ namespace Umbraco.Tests.Testing #region Accessors protected ILogger Logger => Factory.GetInstance(); + protected IJsonSerializer JsonNetSerializer { get; } = new JsonNetSerializer(); protected IIOHelper IOHelper { get; private set; } protected IDataTypeService DataTypeService => Factory.GetInstance(); diff --git a/src/Umbraco.Web/Cache/DistributedCacheBinder.cs b/src/Umbraco.Web/Cache/DistributedCacheBinder.cs index 92ed7de881..0c9b0e75bf 100644 --- a/src/Umbraco.Web/Cache/DistributedCacheBinder.cs +++ b/src/Umbraco.Web/Cache/DistributedCacheBinder.cs @@ -6,6 +6,7 @@ using System.Reflection; using Umbraco.Core; using Umbraco.Core.Events; using Umbraco.Core.Logging; +using Umbraco.Core.Serialization; namespace Umbraco.Web.Cache { @@ -18,14 +19,16 @@ namespace Umbraco.Web.Cache private readonly DistributedCache _distributedCache; private readonly IUmbracoContextFactory _umbracoContextFactory; private readonly ILogger _logger; + private readonly IJsonSerializer _jsonSerializer; /// /// Initializes a new instance of the class. /// - public DistributedCacheBinder(DistributedCache distributedCache, IUmbracoContextFactory umbracoContextFactory, ILogger logger) + public DistributedCacheBinder(DistributedCache distributedCache, IUmbracoContextFactory umbracoContextFactory, ILogger logger, IJsonSerializer jsonSerializer) { _distributedCache = distributedCache; _logger = logger; + _jsonSerializer = jsonSerializer; _umbracoContextFactory = umbracoContextFactory; } diff --git a/src/Umbraco.Web/Cache/DistributedCacheBinder_Handlers.cs b/src/Umbraco.Web/Cache/DistributedCacheBinder_Handlers.cs index c56b7a094f..db8fa35486 100644 --- a/src/Umbraco.Web/Cache/DistributedCacheBinder_Handlers.cs +++ b/src/Umbraco.Web/Cache/DistributedCacheBinder_Handlers.cs @@ -390,13 +390,13 @@ namespace Umbraco.Web.Cache private void MacroService_Deleted(IMacroService sender, DeleteEventArgs e) { foreach (var entity in e.DeletedEntities) - _distributedCache.RemoveMacroCache(entity); + _distributedCache.RemoveMacroCache(_jsonSerializer, entity); } private void MacroService_Saved(IMacroService sender, SaveEventArgs e) { foreach (var entity in e.SavedEntities) - _distributedCache.RefreshMacroCache(entity); + _distributedCache.RefreshMacroCache(_jsonSerializer, entity); } #endregion diff --git a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs index b00a4818f6..8529518af2 100644 --- a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs +++ b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs @@ -1,5 +1,6 @@ using System.Linq; using Umbraco.Core.Models; +using Umbraco.Core.Serialization; using Umbraco.Core.Services.Changes; namespace Umbraco.Web.Cache @@ -189,16 +190,16 @@ namespace Umbraco.Web.Cache #region MacroCache - public static void RefreshMacroCache(this DistributedCache dc, IMacro macro) + public static void RefreshMacroCache(this DistributedCache dc, IJsonSerializer jsonSerializer, IMacro macro) { if (macro == null) return; - dc.RefreshByJson(MacroCacheRefresher.UniqueId, MacroCacheRefresher.Serialize(macro)); + dc.RefreshByJson(MacroCacheRefresher.UniqueId, MacroCacheRefresher.Serialize(jsonSerializer, macro)); } - public static void RemoveMacroCache(this DistributedCache dc, IMacro macro) + public static void RemoveMacroCache(this DistributedCache dc, IJsonSerializer jsonSerializer, IMacro macro) { if (macro == null) return; - dc.RefreshByJson(MacroCacheRefresher.UniqueId, MacroCacheRefresher.Serialize(macro)); + dc.RefreshByJson(MacroCacheRefresher.UniqueId, MacroCacheRefresher.Serialize(jsonSerializer, macro)); } #endregion diff --git a/src/Umbraco.Web/CacheHelperExtensions.cs b/src/Umbraco.Web/CacheHelperExtensions.cs index 615e6a3982..08d1906980 100644 --- a/src/Umbraco.Web/CacheHelperExtensions.cs +++ b/src/Umbraco.Web/CacheHelperExtensions.cs @@ -12,9 +12,6 @@ namespace Umbraco.Web /// public static class CacheHelperExtensions { - - public const string PartialViewCacheKey = "Umbraco.Web.PartialViewCacheKey"; - /// /// Outputs and caches a partial view in MVC /// @@ -43,18 +40,10 @@ namespace Umbraco.Web } return appCaches.RuntimeCache.GetCacheItem( - PartialViewCacheKey + cacheKey, + Core.CacheHelperExtensions.PartialViewCacheKey + cacheKey, () => htmlHelper.Partial(partialViewName, model, viewData), timeout: new TimeSpan(0, 0, 0, cachedSeconds)); } - /// - /// Clears the cache for partial views - /// - /// - public static void ClearPartialViewCache(this AppCaches appCaches) - { - appCaches.RuntimeCache.ClearByKey(PartialViewCacheKey); - } } } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs index 49f64a7e1a..e2b1185120 100755 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs @@ -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, IIdkMap idkMap, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IProfilingLogger logger, IScopeProvider scopeProvider, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IDefaultCultureAccessor defaultCultureAccessor, diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 2a8b5ec0c6..3c813049a2 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -137,9 +137,6 @@ - - - @@ -364,7 +361,6 @@ - @@ -468,8 +464,6 @@ - - @@ -485,10 +479,6 @@ - - - - @@ -522,7 +512,6 @@ - @@ -635,22 +624,7 @@ - - - - - - - - - - - - - - - @@ -958,9 +932,6 @@ - - -