AB4635 - Moved CacheRefreshers to abstractions

This commit is contained in:
Bjarke Berg
2020-01-21 13:40:23 +01:00
parent 928f774bfd
commit 0cdd6ba29d
53 changed files with 122 additions and 116 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,10 +15,10 @@ namespace Umbraco.Web.Cache
public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCacheRefresher, ContentCacheRefresher.JsonPayload>
{
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;
@@ -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;
@@ -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;
@@ -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
{
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using Umbraco.Core.Events;
using Umbraco.Core.Services.Implement;
namespace Umbraco.Web.Cache
{
@@ -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<MacroCacheRefresher>
{
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<JsonPayload[]>(json);
return jsonSerializer.Deserialize<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)
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
@@ -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<MediaCacheRefresher, MediaCacheRefresher.JsonPayload>
{
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<IMedia>();
@@ -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<MemberCacheRefresher, IMember>
{
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<IMember>();
if (memberCache)
@@ -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<MemberGroupCacheRefresher>
{
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<JsonPayload[]>(json);
return _jsonSerializer.Deserialize<JsonPayload[]>(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
@@ -8,10 +8,10 @@ namespace Umbraco.Web.Cache
{
public sealed class TemplateCacheRefresher : CacheRefresherBase<TemplateCacheRefresher>
{
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;
@@ -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,17 @@
using System;
using Umbraco.Core.Models;
namespace Umbraco.Core.Services
{
public interface IIdkMap
{
void SetMapper(UmbracoObjectTypes umbracoObjectType, Func<int, Guid> id2key, Func<Guid, int> key2id);
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);
}
}
@@ -24,7 +24,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions
composition.RegisterUnique<ServiceContext>();
// register the special idk map
composition.RegisterUnique<IdkMap>();
composition.RegisterUnique<IIdkMap, IdkMap>();
// 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,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();
@@ -19,9 +19,9 @@ 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 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;
@@ -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;
}
}
@@ -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);
}
}
@@ -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>());
_h1 = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), JsonNetSerializer);
_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>());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), JsonNetSerializer);
_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>());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), 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<IUmbracoContextFactory>(), Mock.Of<ILogger>());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), 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<IUmbracoContextFactory>(), Mock.Of<ILogger>());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), JsonNetSerializer);
_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>());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), 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<IUmbracoContextFactory>(), Mock.Of<ILogger>());
_distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(Current.ServerMessenger, Current.CacheRefreshers), Mock.Of<IUmbracoContextFactory>(), Mock.Of<ILogger>(), JsonNetSerializer);
_distributedCacheBinder.BindEvents(true);
// check xml in context = "before"
@@ -108,6 +108,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>();
@@ -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;
/// <summary>
/// Initializes a new instance of the <see cref="DistributedCacheBinder"/> class.
/// </summary>
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;
}
@@ -390,13 +390,13 @@ namespace Umbraco.Web.Cache
private void MacroService_Deleted(IMacroService sender, DeleteEventArgs<IMacro> e)
{
foreach (var entity in e.DeletedEntities)
_distributedCache.RemoveMacroCache(entity);
_distributedCache.RemoveMacroCache(_jsonSerializer, entity);
}
private void MacroService_Saved(IMacroService sender, SaveEventArgs<IMacro> e)
{
foreach (var entity in e.SavedEntities)
_distributedCache.RefreshMacroCache(entity);
_distributedCache.RefreshMacroCache(_jsonSerializer, entity);
}
#endregion
@@ -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
+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);
}
}
}
@@ -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,
-29
View File
@@ -137,9 +137,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" />
@@ -364,7 +361,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" />
@@ -468,8 +464,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" />
@@ -485,10 +479,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" />
@@ -522,7 +512,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\UrlInfo.cs" />
<Compile Include="Routing\UrlProviderCollection.cs" />
@@ -635,22 +624,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" />
@@ -958,9 +932,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">