diff --git a/src/Umbraco.Core/Cache/AppCacheExtensions.cs b/src/Umbraco.Abstractions/Cache/AppCacheExtensions.cs similarity index 84% rename from src/Umbraco.Core/Cache/AppCacheExtensions.cs rename to src/Umbraco.Abstractions/Cache/AppCacheExtensions.cs index ddba8be1b2..cbefb5d5c0 100644 --- a/src/Umbraco.Core/Cache/AppCacheExtensions.cs +++ b/src/Umbraco.Abstractions/Cache/AppCacheExtensions.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Web.Caching; namespace Umbraco.Core.Cache { @@ -15,11 +14,9 @@ namespace Umbraco.Core.Cache Func getCacheItem, TimeSpan? timeout, bool isSliding = false, - CacheItemPriority priority = CacheItemPriority.Normal, - CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { - var result = provider.Get(cacheKey, () => getCacheItem(), timeout, isSliding, priority, removedCallback, dependentFiles); + var result = provider.Get(cacheKey, () => getCacheItem(), timeout, isSliding, dependentFiles); return result == null ? default(T) : result.TryConvertTo().Result; } @@ -28,11 +25,9 @@ namespace Umbraco.Core.Cache Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, - CacheItemPriority priority = CacheItemPriority.Normal, - CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { - provider.Insert(cacheKey, () => getCacheItem(), timeout, isSliding, priority, removedCallback, dependentFiles); + provider.Insert(cacheKey, () => getCacheItem(), timeout, isSliding, dependentFiles); } public static IEnumerable GetCacheItemsByKeySearch(this IAppCache provider, string keyStartsWith) diff --git a/src/Umbraco.Core/Cache/AppCaches.cs b/src/Umbraco.Abstractions/Cache/AppCaches.cs similarity index 81% rename from src/Umbraco.Core/Cache/AppCaches.cs rename to src/Umbraco.Abstractions/Cache/AppCaches.cs index fbfc4c8c82..5e8c460ae4 100644 --- a/src/Umbraco.Core/Cache/AppCaches.cs +++ b/src/Umbraco.Abstractions/Cache/AppCaches.cs @@ -1,5 +1,4 @@ using System; -using System.Web; namespace Umbraco.Core.Cache { @@ -8,23 +7,6 @@ namespace Umbraco.Core.Cache /// public class AppCaches { - /// - /// Initializes a new instance of the for use in a web application. - /// - public AppCaches() - : this(HttpRuntime.Cache) - { } - - /// - /// Initializes a new instance of the for use in a web application. - /// - public AppCaches(System.Web.Caching.Cache cache) - : this( - new WebCachingAppCache(cache), - new HttpRequestAppCache(), - new IsolatedCaches(t => new ObjectCacheAppCache())) - { } - /// /// Initializes a new instance of the with cache providers. /// diff --git a/src/Umbraco.Core/Cache/AppPolicedCacheDictionary.cs b/src/Umbraco.Abstractions/Cache/AppPolicedCacheDictionary.cs similarity index 87% rename from src/Umbraco.Core/Cache/AppPolicedCacheDictionary.cs rename to src/Umbraco.Abstractions/Cache/AppPolicedCacheDictionary.cs index 5c60dededa..fa13ebf088 100644 --- a/src/Umbraco.Core/Cache/AppPolicedCacheDictionary.cs +++ b/src/Umbraco.Abstractions/Cache/AppPolicedCacheDictionary.cs @@ -17,24 +17,24 @@ namespace Umbraco.Core.Cache /// protected AppPolicedCacheDictionary(Func cacheFactory) { - CacheFactory = cacheFactory; + _cacheFactory = cacheFactory; } /// /// Gets the internal cache factory, for tests only! /// - internal readonly Func CacheFactory; + private readonly Func _cacheFactory; /// /// Gets or creates a cache. /// public IAppPolicyCache GetOrCreate(TKey key) - => _caches.GetOrAdd(key, k => CacheFactory(k)); + => _caches.GetOrAdd(key, k => _cacheFactory(k)); /// /// Tries to get a cache. /// - public Attempt Get(TKey key) + protected Attempt Get(TKey key) => _caches.TryGetValue(key, out var cache) ? Attempt.Succeed(cache) : Attempt.Fail(); /// @@ -56,7 +56,7 @@ namespace Umbraco.Core.Cache /// /// Clears a cache. /// - public void ClearCache(TKey key) + protected void ClearCache(TKey key) { if (_caches.TryGetValue(key, out var cache)) cache.Clear(); @@ -71,4 +71,4 @@ namespace Umbraco.Core.Cache cache.Clear(); } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Core/Cache/CacheRefresherBase.cs b/src/Umbraco.Abstractions/Cache/CacheRefresherBase.cs similarity index 100% rename from src/Umbraco.Core/Cache/CacheRefresherBase.cs rename to src/Umbraco.Abstractions/Cache/CacheRefresherBase.cs diff --git a/src/Umbraco.Core/Cache/CacheRefresherCollection.cs b/src/Umbraco.Abstractions/Cache/CacheRefresherCollection.cs similarity index 100% rename from src/Umbraco.Core/Cache/CacheRefresherCollection.cs rename to src/Umbraco.Abstractions/Cache/CacheRefresherCollection.cs diff --git a/src/Umbraco.Core/Cache/CacheRefresherEventArgs.cs b/src/Umbraco.Abstractions/Cache/CacheRefresherEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Cache/CacheRefresherEventArgs.cs rename to src/Umbraco.Abstractions/Cache/CacheRefresherEventArgs.cs diff --git a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs b/src/Umbraco.Abstractions/Cache/DeepCloneAppCache.cs similarity index 84% rename from src/Umbraco.Core/Cache/DeepCloneAppCache.cs rename to src/Umbraco.Abstractions/Cache/DeepCloneAppCache.cs index eff06e2aad..452f897372 100644 --- a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs +++ b/src/Umbraco.Abstractions/Cache/DeepCloneAppCache.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Web.Caching; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; @@ -12,7 +11,7 @@ namespace Umbraco.Core.Cache /// instance, and ensuring that all inserts and returns are deep cloned copies of the cache item, /// when the item is deep-cloneable. /// - internal class DeepCloneAppCache : IAppPolicyCache + public class DeepCloneAppCache : IAppPolicyCache { /// /// Initializes a new instance of the class. @@ -30,7 +29,7 @@ namespace Umbraco.Core.Cache /// /// Gets the inner cache. /// - public IAppPolicyCache InnerCache { get; } + private IAppPolicyCache InnerCache { get; } /// public object Get(string key) @@ -44,7 +43,7 @@ namespace Umbraco.Core.Cache { var cached = InnerCache.Get(key, () => { - var result = FastDictionaryAppCacheBase.GetSafeLazy(factory); + var result = SafeLazy.GetSafeLazy(factory); var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache // do not store null values (backward compat), clone / reset to go into the cache return value == null ? null : CheckCloneableAndTracksChanges(value); @@ -67,32 +66,32 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null) { var cached = InnerCache.Get(key, () => { - var result = FastDictionaryAppCacheBase.GetSafeLazy(factory); + var result = SafeLazy.GetSafeLazy(factory); var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache // do not store null values (backward compat), clone / reset to go into the cache return value == null ? null : CheckCloneableAndTracksChanges(value); // clone / reset to go into the cache - }, timeout, isSliding, priority, removedCallback, dependentFiles); + }, timeout, isSliding, dependentFiles); // clone / reset to go into the cache return CheckCloneableAndTracksChanges(cached); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) { InnerCache.Insert(key, () => { - var result = FastDictionaryAppCacheBase.GetSafeLazy(factory); + var result = SafeLazy.GetSafeLazy(factory); var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache // do not store null values (backward compat), clone / reset to go into the cache return value == null ? null : CheckCloneableAndTracksChanges(value); - }, timeout, isSliding, priority, removedCallback, dependentFiles); + }, timeout, isSliding, dependentFiles); } /// diff --git a/src/Umbraco.Core/Cache/DictionaryAppCache.cs b/src/Umbraco.Abstractions/Cache/DictionaryAppCache.cs similarity index 71% rename from src/Umbraco.Core/Cache/DictionaryAppCache.cs rename to src/Umbraco.Abstractions/Cache/DictionaryAppCache.cs index 8889630ff0..6e528165a0 100644 --- a/src/Umbraco.Core/Cache/DictionaryAppCache.cs +++ b/src/Umbraco.Abstractions/Cache/DictionaryAppCache.cs @@ -13,25 +13,27 @@ namespace Umbraco.Core.Cache /// /// Gets the internal items dictionary, for tests only! /// - internal readonly ConcurrentDictionary Items = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _items = new ConcurrentDictionary(); + + public int Count => _items.Count; /// public virtual object Get(string key) { - return Items.TryGetValue(key, out var value) ? value : null; + return _items.TryGetValue(key, out var value) ? value : null; } /// public virtual object Get(string key, Func factory) { - return Items.GetOrAdd(key, _ => factory()); + return _items.GetOrAdd(key, _ => factory()); } /// public virtual IEnumerable SearchByKey(string keyStartsWith) { var items = new List(); - foreach (var (key, value) in Items) + foreach (var (key, value) in _items) if (key.InvariantStartsWith(keyStartsWith)) items.Add(value); return items; @@ -42,7 +44,7 @@ namespace Umbraco.Core.Cache { var compiled = new Regex(regex, RegexOptions.Compiled); var items = new List(); - foreach (var (key, value) in Items) + foreach (var (key, value) in _items) if (compiled.IsMatch(key)) items.Add(value); return items; @@ -51,46 +53,46 @@ namespace Umbraco.Core.Cache /// public virtual void Clear() { - Items.Clear(); + _items.Clear(); } /// public virtual void Clear(string key) { - Items.TryRemove(key, out _); + _items.TryRemove(key, out _); } /// public virtual void ClearOfType(string typeName) { - Items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType().ToString().InvariantEquals(typeName)); + _items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType().ToString().InvariantEquals(typeName)); } /// public virtual void ClearOfType() { var typeOfT = typeof(T); - Items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT); + _items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT); } /// public virtual void ClearOfType(Func predicate) { var typeOfT = typeof(T); - Items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT && predicate(kvp.Key, (T)kvp.Value)); + _items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT && predicate(kvp.Key, (T)kvp.Value)); } /// public virtual void ClearByKey(string keyStartsWith) { - Items.RemoveAll(kvp => kvp.Key.InvariantStartsWith(keyStartsWith)); + _items.RemoveAll(kvp => kvp.Key.InvariantStartsWith(keyStartsWith)); } /// public virtual void ClearByRegex(string regex) { var compiled = new Regex(regex, RegexOptions.Compiled); - Items.RemoveAll(kvp => compiled.IsMatch(kvp.Key)); + _items.RemoveAll(kvp => compiled.IsMatch(kvp.Key)); } } } diff --git a/src/Umbraco.Core/Cache/IAppPolicyCache.cs b/src/Umbraco.Abstractions/Cache/IAppPolicyCache.cs similarity index 73% rename from src/Umbraco.Core/Cache/IAppPolicyCache.cs rename to src/Umbraco.Abstractions/Cache/IAppPolicyCache.cs index dd162b990d..9746e80804 100644 --- a/src/Umbraco.Core/Cache/IAppPolicyCache.cs +++ b/src/Umbraco.Abstractions/Cache/IAppPolicyCache.cs @@ -1,5 +1,4 @@ using System; -using System.Web.Caching; namespace Umbraco.Core.Cache { @@ -17,8 +16,6 @@ namespace Umbraco.Core.Cache /// A factory function that can create the item. /// An optional cache timeout. /// An optional value indicating whether the cache timeout is sliding (default is false). - /// An optional cache priority (default is Normal). - /// An optional callback to handle removals. /// Files the cache entry depends on. /// The item. object Get( @@ -26,8 +23,6 @@ namespace Umbraco.Core.Cache Func factory, TimeSpan? timeout, bool isSliding = false, - CacheItemPriority priority = CacheItemPriority.Normal, - CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null); /// @@ -37,16 +32,12 @@ namespace Umbraco.Core.Cache /// A factory function that can create the item. /// An optional cache timeout. /// An optional value indicating whether the cache timeout is sliding (default is false). - /// An optional cache priority (default is Normal). - /// An optional callback to handle removals. /// Files the cache entry depends on. void Insert( string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, - CacheItemPriority priority = CacheItemPriority.Normal, - CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null); } } diff --git a/src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs b/src/Umbraco.Abstractions/Cache/IRepositoryCachePolicy.cs similarity index 98% rename from src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs rename to src/Umbraco.Abstractions/Cache/IRepositoryCachePolicy.cs index 020f4f7dd9..a31e715383 100644 --- a/src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs +++ b/src/Umbraco.Abstractions/Cache/IRepositoryCachePolicy.cs @@ -5,7 +5,7 @@ using Umbraco.Core.Scoping; namespace Umbraco.Core.Cache { - internal interface IRepositoryCachePolicy + public interface IRepositoryCachePolicy where TEntity : class, IEntity { /// diff --git a/src/Umbraco.Core/Cache/IsolatedCaches.cs b/src/Umbraco.Abstractions/Cache/IsolatedCaches.cs similarity index 100% rename from src/Umbraco.Core/Cache/IsolatedCaches.cs rename to src/Umbraco.Abstractions/Cache/IsolatedCaches.cs diff --git a/src/Umbraco.Core/Cache/JsonCacheRefresherBase.cs b/src/Umbraco.Abstractions/Cache/JsonCacheRefresherBase.cs similarity index 100% rename from src/Umbraco.Core/Cache/JsonCacheRefresherBase.cs rename to src/Umbraco.Abstractions/Cache/JsonCacheRefresherBase.cs diff --git a/src/Umbraco.Core/Cache/NoAppCache.cs b/src/Umbraco.Abstractions/Cache/NoAppCache.cs similarity index 83% rename from src/Umbraco.Core/Cache/NoAppCache.cs rename to src/Umbraco.Abstractions/Cache/NoAppCache.cs index d3359a30ba..24c51c935a 100644 --- a/src/Umbraco.Core/Cache/NoAppCache.cs +++ b/src/Umbraco.Abstractions/Cache/NoAppCache.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Web.Caching; namespace Umbraco.Core.Cache { @@ -42,13 +41,13 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null) { return factory(); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) { } /// diff --git a/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs b/src/Umbraco.Abstractions/Cache/NoCacheRepositoryCachePolicy.cs similarity index 93% rename from src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs rename to src/Umbraco.Abstractions/Cache/NoCacheRepositoryCachePolicy.cs index fecab66d84..20b57c49ff 100644 --- a/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs +++ b/src/Umbraco.Abstractions/Cache/NoCacheRepositoryCachePolicy.cs @@ -5,7 +5,7 @@ using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Cache { - internal class NoCacheRepositoryCachePolicy : IRepositoryCachePolicy + public class NoCacheRepositoryCachePolicy : IRepositoryCachePolicy where TEntity : class, IEntity { private NoCacheRepositoryCachePolicy() { } diff --git a/src/Umbraco.Core/Cache/PayloadCacheRefresherBase.cs b/src/Umbraco.Abstractions/Cache/PayloadCacheRefresherBase.cs similarity index 79% rename from src/Umbraco.Core/Cache/PayloadCacheRefresherBase.cs rename to src/Umbraco.Abstractions/Cache/PayloadCacheRefresherBase.cs index 4a3a03a0d6..1ee804bc82 100644 --- a/src/Umbraco.Core/Cache/PayloadCacheRefresherBase.cs +++ b/src/Umbraco.Abstractions/Cache/PayloadCacheRefresherBase.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System; +using Umbraco.Core.Serialization; using Umbraco.Core.Sync; namespace Umbraco.Core.Cache @@ -12,12 +13,17 @@ namespace Umbraco.Core.Cache public abstract class PayloadCacheRefresherBase : JsonCacheRefresherBase, IPayloadCacheRefresher where TInstanceType : class, ICacheRefresher { + private readonly IJsonSerializer _serializer; + /// /// Initializes a new instance of the . /// /// A cache helper. - protected PayloadCacheRefresherBase(AppCaches appCaches) : base(appCaches) - { } + /// + protected PayloadCacheRefresherBase(AppCaches appCaches, IJsonSerializer serializer) : base(appCaches) + { + _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); + } #region Json @@ -28,7 +34,7 @@ namespace Umbraco.Core.Cache /// The deserialized object payload. protected virtual TPayload[] Deserialize(string json) { - return JsonConvert.DeserializeObject(json); + return _serializer.Deserialize(json); } #endregion diff --git a/src/Umbraco.Core/Cache/RepositoryCachePolicyOptions.cs b/src/Umbraco.Abstractions/Cache/RepositoryCachePolicyOptions.cs similarity index 97% rename from src/Umbraco.Core/Cache/RepositoryCachePolicyOptions.cs rename to src/Umbraco.Abstractions/Cache/RepositoryCachePolicyOptions.cs index 72baa05564..06095f058d 100644 --- a/src/Umbraco.Core/Cache/RepositoryCachePolicyOptions.cs +++ b/src/Umbraco.Abstractions/Cache/RepositoryCachePolicyOptions.cs @@ -5,7 +5,7 @@ namespace Umbraco.Core.Cache /// /// Specifies how a repository cache policy should cache entities. /// - internal class RepositoryCachePolicyOptions + public class RepositoryCachePolicyOptions { /// /// Ctor - sets GetAllCacheValidateCount = true diff --git a/src/Umbraco.Abstractions/Cache/SafeLazy.cs b/src/Umbraco.Abstractions/Cache/SafeLazy.cs new file mode 100644 index 0000000000..d901a534c6 --- /dev/null +++ b/src/Umbraco.Abstractions/Cache/SafeLazy.cs @@ -0,0 +1,63 @@ +using System; +using System.Runtime.ExceptionServices; + +namespace Umbraco.Core.Cache +{ + public static class SafeLazy + { + // an object that represent a value that has not been created yet + internal static readonly object ValueNotCreated = new object(); + + public static Lazy GetSafeLazy(Func getCacheItem) + { + // try to generate the value and if it fails, + // wrap in an ExceptionHolder - would be much simpler + // to just use lazy.IsValueFaulted alas that field is + // internal + return new Lazy(() => + { + try + { + return getCacheItem(); + } + catch (Exception e) + { + return new ExceptionHolder(ExceptionDispatchInfo.Capture(e)); + } + }); + } + + public static object GetSafeLazyValue(Lazy lazy, bool onlyIfValueIsCreated = false) + { + // if onlyIfValueIsCreated, do not trigger value creation + // must return something, though, to differentiate from null values + if (onlyIfValueIsCreated && lazy.IsValueCreated == false) return ValueNotCreated; + + // if execution has thrown then lazy.IsValueCreated is false + // and lazy.IsValueFaulted is true (but internal) so we use our + // own exception holder (see Lazy source code) to return null + if (lazy.Value is ExceptionHolder) return null; + + // we have a value and execution has not thrown so returning + // here does not throw - unless we're re-entering, take care of it + try + { + return lazy.Value; + } + catch (InvalidOperationException e) + { + throw new InvalidOperationException("The method that computes a value for the cache has tried to read that value from the cache.", e); + } + } + + public class ExceptionHolder + { + public ExceptionHolder(ExceptionDispatchInfo e) + { + Exception = e; + } + + public ExceptionDispatchInfo Exception { get; } + } + } +} diff --git a/src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs b/src/Umbraco.Abstractions/Cache/TypedCacheRefresherBase.cs similarity index 100% rename from src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs rename to src/Umbraco.Abstractions/Cache/TypedCacheRefresherBase.cs diff --git a/src/Umbraco.Abstractions/Serialization/AbstractSerializationService.cs b/src/Umbraco.Abstractions/Serialization/AbstractSerializationService.cs deleted file mode 100644 index db4afba3e8..0000000000 --- a/src/Umbraco.Abstractions/Serialization/AbstractSerializationService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; - -namespace Umbraco.Core.Serialization -{ - public abstract class AbstractSerializationService - { - /// - /// A sequence of registered with this serialization service. - /// - public IEnumerable Formatters { get; set; } - - /// - /// Finds an with a matching , and deserializes the to an object graph. - /// - /// - /// - /// - /// - public abstract object FromStream(Stream input, Type outputType, string intent = null); - - /// - /// Finds an with a matching , and serializes the object graph to an . - /// - /// - /// - /// - public abstract IStreamedResult ToStream(object input, string intent = null); - } -} diff --git a/src/Umbraco.Abstractions/Serialization/Formatter.cs b/src/Umbraco.Abstractions/Serialization/Formatter.cs deleted file mode 100644 index bfdabbe13f..0000000000 --- a/src/Umbraco.Abstractions/Serialization/Formatter.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace Umbraco.Core.Serialization -{ - public class Formatter : IFormatter - { - #region Implementation of IFormatter - - public string Intent - { - get { throw new NotImplementedException(); } - } - - public ISerializer Serializer - { - get { throw new NotImplementedException(); } - } - - #endregion - } -} diff --git a/src/Umbraco.Abstractions/Serialization/IFormatter.cs b/src/Umbraco.Abstractions/Serialization/IFormatter.cs deleted file mode 100644 index 5c34819a18..0000000000 --- a/src/Umbraco.Abstractions/Serialization/IFormatter.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Umbraco.Core.Serialization -{ - public interface IFormatter - { - string Intent { get; } - - ISerializer Serializer { get; } - } -} diff --git a/src/Umbraco.Abstractions/Serialization/IJsonSerializer.cs b/src/Umbraco.Abstractions/Serialization/IJsonSerializer.cs new file mode 100644 index 0000000000..c619f173fe --- /dev/null +++ b/src/Umbraco.Abstractions/Serialization/IJsonSerializer.cs @@ -0,0 +1,9 @@ +namespace Umbraco.Core.Serialization +{ + public interface IJsonSerializer + { + string Serialize(object input); + + T Deserialize(string input); + } +} diff --git a/src/Umbraco.Abstractions/Serialization/ISerializer.cs b/src/Umbraco.Abstractions/Serialization/ISerializer.cs deleted file mode 100644 index 329d7a9109..0000000000 --- a/src/Umbraco.Abstractions/Serialization/ISerializer.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.IO; - -namespace Umbraco.Core.Serialization -{ - public interface ISerializer - { - object FromStream(Stream input, Type outputType); - - IStreamedResult ToStream(object input); - } -} diff --git a/src/Umbraco.Abstractions/Serialization/IStreamedResult.cs b/src/Umbraco.Abstractions/Serialization/IStreamedResult.cs deleted file mode 100644 index 0c6e6078cb..0000000000 --- a/src/Umbraco.Abstractions/Serialization/IStreamedResult.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.IO; - -namespace Umbraco.Core.Serialization -{ - public interface IStreamedResult - { - Stream ResultStream { get; } - bool Success { get; } - } -} diff --git a/src/Umbraco.Abstractions/Serialization/SerializationService.cs b/src/Umbraco.Abstractions/Serialization/SerializationService.cs deleted file mode 100644 index dee9712552..0000000000 --- a/src/Umbraco.Abstractions/Serialization/SerializationService.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.IO; - -namespace Umbraco.Core.Serialization -{ - public class SerializationService : AbstractSerializationService - { - private readonly ISerializer _serializer; - - public SerializationService(ISerializer serializer) - { - _serializer = serializer; - } - - #region Overrides of AbstractSerializationService - - /// - /// Finds an with a matching , and deserializes the to an object graph. - /// - /// - /// - /// - /// - public override object FromStream(Stream input, Type outputType, string intent = null) - { - if (input.CanSeek && input.Position > 0) input.Seek(0, SeekOrigin.Begin); - return _serializer.FromStream(input, outputType); - } - - /// - /// Finds an with a matching , and serializes the object graph to an . - /// - /// - /// - /// - public override IStreamedResult ToStream(object input, string intent = null) - { - return _serializer.ToStream(input); - } - - #endregion - } -} diff --git a/src/Umbraco.Abstractions/Serialization/StreamResultExtensions.cs b/src/Umbraco.Abstractions/Serialization/StreamResultExtensions.cs deleted file mode 100644 index 3d8d2cb924..0000000000 --- a/src/Umbraco.Abstractions/Serialization/StreamResultExtensions.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.IO; -using System.Text; -using System.Xml.Linq; - -namespace Umbraco.Core.Serialization -{ - public static class StreamResultExtensions - { - public static string ToJsonString(this Stream stream) - { - byte[] bytes = new byte[stream.Length]; - stream.Position = 0; - stream.Read(bytes, 0, (int)stream.Length); - return Encoding.UTF8.GetString(bytes); - } - - public static XDocument ToXDoc(this Stream stream) - { - return XDocument.Load(stream); - } - } -} diff --git a/src/Umbraco.Abstractions/Serialization/StreamedResult.cs b/src/Umbraco.Abstractions/Serialization/StreamedResult.cs deleted file mode 100644 index d1c42e976c..0000000000 --- a/src/Umbraco.Abstractions/Serialization/StreamedResult.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.IO; - -namespace Umbraco.Core.Serialization -{ - public class StreamedResult : IStreamedResult - { - public StreamedResult(Stream stream, bool success) - { - ResultStream = stream; - Success = success; - } - - #region Implementation of IStreamedResult - - public Stream ResultStream { get; protected set; } - - public bool Success { get; protected set; } - - #endregion - } -} diff --git a/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj b/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj index 4a3654ede6..a5e5a94520 100644 --- a/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj +++ b/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj @@ -6,4 +6,8 @@ Umbraco.Core + + + + diff --git a/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs b/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs index c11309c827..e4102e8684 100644 --- a/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs +++ b/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs @@ -17,7 +17,7 @@ namespace Umbraco.Core.Cache /// If options.GetAllCacheAllowZeroCount then a 'zero-count' array is cached when GetAll finds nothing. /// If options.GetAllCacheValidateCount then we check against the db when getting many entities. /// - internal class DefaultRepositoryCachePolicy : RepositoryCachePolicyBase + public class DefaultRepositoryCachePolicy : RepositoryCachePolicyBase where TEntity : class, IEntity { private static readonly TEntity[] EmptyEntities = new TEntity[0]; // const diff --git a/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs b/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs index bd545694f7..b38f36a7d8 100644 --- a/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs +++ b/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs @@ -21,16 +21,16 @@ namespace Umbraco.Core.Cache public object Get(string cacheKey) { Items.TryGetValue(cacheKey, out var result); // else null - return result == null ? null : FastDictionaryAppCacheBase.GetSafeLazyValue(result); // return exceptions as null + return result == null ? null : SafeLazy.GetSafeLazyValue(result); // return exceptions as null } /// public object Get(string cacheKey, Func getCacheItem) { - var result = Items.GetOrAdd(cacheKey, k => FastDictionaryAppCacheBase.GetSafeLazy(getCacheItem)); + var result = Items.GetOrAdd(cacheKey, k => SafeLazy.GetSafeLazy(getCacheItem)); var value = result.Value; // will not throw (safe lazy) - if (!(value is FastDictionaryAppCacheBase.ExceptionHolder eh)) + if (!(value is SafeLazy.ExceptionHolder eh)) return value; // and... it's in the cache anyway - so contrary to other cache providers, @@ -47,7 +47,7 @@ namespace Umbraco.Core.Cache { return Items .Where(kvp => kvp.Key.InvariantStartsWith(keyStartsWith)) - .Select(kvp => FastDictionaryAppCacheBase.GetSafeLazyValue(kvp.Value)) + .Select(kvp => SafeLazy.GetSafeLazyValue(kvp.Value)) .Where(x => x != null); } @@ -57,7 +57,7 @@ namespace Umbraco.Core.Cache var compiled = new Regex(regex, RegexOptions.Compiled); return Items .Where(kvp => compiled.IsMatch(kvp.Key)) - .Select(kvp => FastDictionaryAppCacheBase.GetSafeLazyValue(kvp.Value)) + .Select(kvp => SafeLazy.GetSafeLazyValue(kvp.Value)) .Where(x => x != null); } @@ -86,7 +86,7 @@ namespace Umbraco.Core.Cache // entry.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue(x.Value, true); + var value = SafeLazy.GetSafeLazyValue(x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -108,7 +108,7 @@ namespace Umbraco.Core.Cache // remove null values as well, does not hurt // compare on exact type, don't use "is" // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue(x.Value, true); + var value = SafeLazy.GetSafeLazyValue(x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -130,7 +130,7 @@ namespace Umbraco.Core.Cache // remove null values as well, does not hurt // compare on exact type, don't use "is" // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue(x.Value, true); + var value = SafeLazy.GetSafeLazyValue(x.Value, true); if (value == null) return true; // if T is an interface remove anything that implements that interface diff --git a/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs b/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs index 21e2b63597..eb84423f32 100644 --- a/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs +++ b/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Runtime.ExceptionServices; using System.Text.RegularExpressions; using Umbraco.Core.Composing; @@ -16,9 +15,6 @@ namespace Umbraco.Core.Cache // prefix cache keys so we know which one are ours protected const string CacheItemPrefix = "umbrtmche"; - // an object that represent a value that has not been created yet - protected internal static readonly object ValueNotCreated = new object(); - #region IAppCache /// @@ -35,7 +31,7 @@ namespace Umbraco.Core.Cache { ExitReadLock(); } - return result == null ? null : GetSafeLazyValue(result); // return exceptions as null + return result == null ? null : SafeLazy.GetSafeLazyValue(result); // return exceptions as null } /// @@ -59,7 +55,7 @@ namespace Umbraco.Core.Cache } return entries - .Select(x => GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null .Where(x => x != null); // backward compat, don't store null values in the cache } @@ -82,7 +78,7 @@ namespace Umbraco.Core.Cache ExitReadLock(); } return entries - .Select(x => GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null .Where(x => x != null); // backward compatible, don't store null values in the cache } @@ -132,7 +128,7 @@ namespace Umbraco.Core.Cache // entry.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = GetSafeLazyValue((Lazy) x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -162,7 +158,7 @@ namespace Umbraco.Core.Cache // remove null values as well, does not hurt // compare on exact type, don't use "is" // get non-created as NonCreatedValue & exceptions as null - var value = GetSafeLazyValue((Lazy) x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -193,7 +189,7 @@ namespace Umbraco.Core.Cache // remove null values as well, does not hurt // compare on exact type, don't use "is" // get non-created as NonCreatedValue & exceptions as null - var value = GetSafeLazyValue((Lazy) x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); if (value == null) return true; // if T is an interface remove anything that implements that interface @@ -272,57 +268,7 @@ namespace Umbraco.Core.Cache return $"{CacheItemPrefix}-{key}"; } - protected internal static Lazy GetSafeLazy(Func getCacheItem) - { - // try to generate the value and if it fails, - // wrap in an ExceptionHolder - would be much simpler - // to just use lazy.IsValueFaulted alas that field is - // internal - return new Lazy(() => - { - try - { - return getCacheItem(); - } - catch (Exception e) - { - return new ExceptionHolder(ExceptionDispatchInfo.Capture(e)); - } - }); - } - - protected internal static object GetSafeLazyValue(Lazy lazy, bool onlyIfValueIsCreated = false) - { - // if onlyIfValueIsCreated, do not trigger value creation - // must return something, though, to differentiate from null values - if (onlyIfValueIsCreated && lazy.IsValueCreated == false) return ValueNotCreated; - - // if execution has thrown then lazy.IsValueCreated is false - // and lazy.IsValueFaulted is true (but internal) so we use our - // own exception holder (see Lazy source code) to return null - if (lazy.Value is ExceptionHolder) return null; - - // we have a value and execution has not thrown so returning - // here does not throw - unless we're re-entering, take care of it - try - { - return lazy.Value; - } - catch (InvalidOperationException e) - { - throw new InvalidOperationException("The method that computes a value for the cache has tried to read that value from the cache.", e); - } - } - - internal class ExceptionHolder - { - public ExceptionHolder(ExceptionDispatchInfo e) - { - Exception = e; - } - - public ExceptionDispatchInfo Exception { get; } - } + #endregion } diff --git a/src/Umbraco.Core/Cache/HttpRequestAppCache.cs b/src/Umbraco.Core/Cache/HttpRequestAppCache.cs index eeebcd2622..018726538b 100644 --- a/src/Umbraco.Core/Cache/HttpRequestAppCache.cs +++ b/src/Umbraco.Core/Cache/HttpRequestAppCache.cs @@ -60,9 +60,9 @@ namespace Umbraco.Core.Cache // do nothing here - means that if creation throws, a race condition could cause // more than one thread to reach the return statement below and throw - accepted. - if (result == null || GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null + if (result == null || SafeLazy.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { - result = GetSafeLazy(factory); + result = SafeLazy.GetSafeLazy(factory); ContextItems[key] = result; } } @@ -79,7 +79,7 @@ namespace Umbraco.Core.Cache //return result.Value; var value = result.Value; // will not throw (safe lazy) - if (value is ExceptionHolder eh) eh.Exception.Throw(); // throw once! + if (value is SafeLazy.ExceptionHolder eh) eh.Exception.Throw(); // throw once! return value; } diff --git a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs index 5c4f76f51d..ad7f3d6bf7 100644 --- a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs +++ b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs @@ -4,9 +4,7 @@ using System.Linq; using System.Runtime.Caching; using System.Text.RegularExpressions; using System.Threading; -using System.Web.Caching; using Umbraco.Core.Composing; -using CacheItemPriority = System.Web.Caching.CacheItemPriority; namespace Umbraco.Core.Cache { @@ -47,7 +45,7 @@ namespace Umbraco.Core.Cache if (_locker.IsReadLockHeld) _locker.ExitReadLock(); } - return result == null ? null : FastDictionaryAppCacheBase.GetSafeLazyValue(result); // return exceptions as null + return result == null ? null : SafeLazy.GetSafeLazyValue(result); // return exceptions as null } /// @@ -73,7 +71,7 @@ namespace Umbraco.Core.Cache _locker.ExitReadLock(); } return entries - .Select(x => FastDictionaryAppCacheBase.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null .Where(x => x != null) // backward compat, don't store null values in the cache .ToList(); } @@ -97,13 +95,13 @@ namespace Umbraco.Core.Cache _locker.ExitReadLock(); } return entries - .Select(x => FastDictionaryAppCacheBase.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null .Where(x => x != null) // backward compat, don't store null values in the cache .ToList(); } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null) { // see notes in HttpRuntimeAppCache @@ -112,10 +110,10 @@ namespace Umbraco.Core.Cache using (var lck = new UpgradeableReadLock(_locker)) { result = MemoryCache.Get(key) as Lazy; - if (result == null || FastDictionaryAppCacheBase.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null + if (result == null || SafeLazy.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { - result = FastDictionaryAppCacheBase.GetSafeLazy(factory); - var policy = GetPolicy(timeout, isSliding, removedCallback, dependentFiles); + result = SafeLazy.GetSafeLazy(factory); + var policy = GetPolicy(timeout, isSliding, dependentFiles); lck.UpgradeToWriteLock(); //NOTE: This does an add or update @@ -126,21 +124,21 @@ namespace Umbraco.Core.Cache //return result.Value; var value = result.Value; // will not throw (safe lazy) - if (value is FastDictionaryAppCacheBase.ExceptionHolder eh) eh.Exception.Throw(); // throw once! + if (value is SafeLazy.ExceptionHolder eh) eh.Exception.Throw(); // throw once! return value; } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) { // NOTE - here also we must insert a Lazy but we can evaluate it right now // and make sure we don't store a null value. - var result = FastDictionaryAppCacheBase.GetSafeLazy(factory); + var result = SafeLazy.GetSafeLazy(factory); var value = result.Value; // force evaluation now if (value == null) return; // do not store null values (backward compat) - var policy = GetPolicy(timeout, isSliding, removedCallback, dependentFiles); + var policy = GetPolicy(timeout, isSliding, dependentFiles); //NOTE: This does an add or update MemoryCache.Set(key, result, policy); } @@ -192,7 +190,7 @@ namespace Umbraco.Core.Cache // x.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue((Lazy)x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -223,7 +221,7 @@ namespace Umbraco.Core.Cache // x.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue((Lazy)x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -255,7 +253,7 @@ namespace Umbraco.Core.Cache // x.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue((Lazy)x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); if (value == null) return true; // if T is an interface remove anything that implements that interface @@ -314,7 +312,7 @@ namespace Umbraco.Core.Cache } } - private static CacheItemPolicy GetPolicy(TimeSpan? timeout = null, bool isSliding = false, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + private static CacheItemPolicy GetPolicy(TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) { var absolute = isSliding ? ObjectCache.InfiniteAbsoluteExpiration : (timeout == null ? ObjectCache.InfiniteAbsoluteExpiration : DateTime.Now.Add(timeout.Value)); var sliding = isSliding == false ? ObjectCache.NoSlidingExpiration : (timeout ?? ObjectCache.NoSlidingExpiration); @@ -330,34 +328,6 @@ namespace Umbraco.Core.Cache policy.ChangeMonitors.Add(new HostFileChangeMonitor(dependentFiles.ToList())); } - if (removedCallback != null) - { - policy.RemovedCallback = arguments => - { - //convert the reason - var reason = CacheItemRemovedReason.Removed; - switch (arguments.RemovedReason) - { - case CacheEntryRemovedReason.Removed: - reason = CacheItemRemovedReason.Removed; - break; - case CacheEntryRemovedReason.Expired: - reason = CacheItemRemovedReason.Expired; - break; - case CacheEntryRemovedReason.Evicted: - reason = CacheItemRemovedReason.Underused; - break; - case CacheEntryRemovedReason.ChangeMonitorChanged: - reason = CacheItemRemovedReason.Expired; - break; - case CacheEntryRemovedReason.CacheSpecificEviction: - reason = CacheItemRemovedReason.Underused; - break; - } - //call the callback - removedCallback(arguments.CacheItem.Key, arguments.CacheItem.Value, reason); - }; - } return policy; } } diff --git a/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs b/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs index 27fe4e3035..33258cbf06 100644 --- a/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs +++ b/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.Cache /// /// The type of the entity. /// The type of the identifier. - internal abstract class RepositoryCachePolicyBase : IRepositoryCachePolicy + public abstract class RepositoryCachePolicyBase : IRepositoryCachePolicy where TEntity : class, IEntity { private readonly IAppPolicyCache _globalCache; diff --git a/src/Umbraco.Core/Cache/WebCachingAppCache.cs b/src/Umbraco.Core/Cache/WebCachingAppCache.cs index c6e104221a..362df8f603 100644 --- a/src/Umbraco.Core/Cache/WebCachingAppCache.cs +++ b/src/Umbraco.Core/Cache/WebCachingAppCache.cs @@ -35,25 +35,25 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null) { CacheDependency dependency = null; if (dependentFiles != null && dependentFiles.Any()) { dependency = new CacheDependency(dependentFiles); } - return Get(key, factory, timeout, isSliding, priority, removedCallback, dependency); + return GetImpl(key, factory, timeout, isSliding, dependency); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) { CacheDependency dependency = null; if (dependentFiles != null && dependentFiles.Any()) { dependency = new CacheDependency(dependentFiles); } - Insert(key, factory, timeout, isSliding, priority, removedCallback, dependency); + InsertImpl(key, factory, timeout, isSliding, dependency); } #region Dictionary @@ -103,7 +103,7 @@ namespace Umbraco.Core.Cache #endregion - private object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, CacheDependency dependency = null) + private object GetImpl(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheDependency dependency = null) { key = GetCacheKey(key); @@ -145,7 +145,7 @@ namespace Umbraco.Core.Cache if (_locker.IsReadLockHeld) _locker.ExitReadLock(); } - var value = result == null ? null : GetSafeLazyValue(result); + var value = result == null ? null : SafeLazy.GetSafeLazyValue(result); if (value != null) return value; using (var lck = new UpgradeableReadLock(_locker)) @@ -156,15 +156,15 @@ namespace Umbraco.Core.Cache // do nothing here - means that if creation throws, a race condition could cause // more than one thread to reach the return statement below and throw - accepted. - if (result == null || GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null + if (result == null || SafeLazy.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { - result = GetSafeLazy(factory); + result = SafeLazy.GetSafeLazy(factory); var absolute = isSliding ? System.Web.Caching.Cache.NoAbsoluteExpiration : (timeout == null ? System.Web.Caching.Cache.NoAbsoluteExpiration : DateTime.Now.Add(timeout.Value)); var sliding = isSliding == false ? System.Web.Caching.Cache.NoSlidingExpiration : (timeout ?? System.Web.Caching.Cache.NoSlidingExpiration); lck.UpgradeToWriteLock(); //NOTE: 'Insert' on System.Web.Caching.Cache actually does an add or update! - _cache.Insert(key, result, dependency, absolute, sliding, priority, removedCallback); + _cache.Insert(key, result, dependency, absolute, sliding, CacheItemPriority.Normal, null); } } @@ -176,16 +176,16 @@ namespace Umbraco.Core.Cache //return result.Value; value = result.Value; // will not throw (safe lazy) - if (value is ExceptionHolder eh) eh.Exception.Throw(); // throw once! + if (value is SafeLazy.ExceptionHolder eh) eh.Exception.Throw(); // throw once! return value; } - private void Insert(string cacheKey, Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, CacheDependency dependency = null) + private void InsertImpl(string cacheKey, Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, CacheDependency dependency = null) { // NOTE - here also we must insert a Lazy but we can evaluate it right now // and make sure we don't store a null value. - var result = GetSafeLazy(getCacheItem); + var result = SafeLazy.GetSafeLazy(getCacheItem); var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache if (value == null) return; // do not store null values (backward compat) @@ -198,7 +198,7 @@ namespace Umbraco.Core.Cache { _locker.EnterWriteLock(); //NOTE: 'Insert' on System.Web.Caching.Cache actually does an add or update! - _cache.Insert(cacheKey, result, dependency, absolute, sliding, priority, removedCallback); + _cache.Insert(cacheKey, result, dependency, absolute, sliding, CacheItemPriority.Normal, null); } finally { diff --git a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs index 1f004846d0..bc521b0328 100644 --- a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs @@ -17,6 +17,7 @@ using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; using Umbraco.Core.Scoping; +using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Core.Sync; @@ -50,6 +51,8 @@ namespace Umbraco.Core.Runtime composition.RegisterUnique(f => f.GetInstance()); composition.RegisterUnique(f => f.GetInstance()); + composition.RegisterUnique(); + // register database builder // *not* a singleton, don't want to keep it around composition.Register(); diff --git a/src/Umbraco.Core/Serialization/JsonNetSerializer.cs b/src/Umbraco.Core/Serialization/JsonNetSerializer.cs index 46f23ca35e..a2a5f19082 100644 --- a/src/Umbraco.Core/Serialization/JsonNetSerializer.cs +++ b/src/Umbraco.Core/Serialization/JsonNetSerializer.cs @@ -1,72 +1,22 @@ using System; -using System.IO; -using System.Reflection; +using System.Collections.Generic; +using System.Linq; using System.Text; +using System.Threading.Tasks; using Newtonsoft.Json; -using Newtonsoft.Json.Converters; namespace Umbraco.Core.Serialization { - internal class JsonNetSerializer : ISerializer + public class JsonNetSerializer : IJsonSerializer { - private readonly JsonSerializerSettings _settings; - - public JsonNetSerializer() + public string Serialize(object input) { - _settings = new JsonSerializerSettings(); - - //var customResolver = new CustomIgnoreResolver - // { - // DefaultMembersSearchFlags = BindingFlags.Instance | BindingFlags.Public - // }; - //_settings.ContractResolver = customResolver; - - var javaScriptDateTimeConverter = new JavaScriptDateTimeConverter(); - - _settings.Converters.Add(javaScriptDateTimeConverter); - _settings.Converters.Add(new EntityKeyMemberConverter()); - _settings.Converters.Add(new KeyValuePairConverter()); - _settings.Converters.Add(new ExpandoObjectConverter()); - _settings.Converters.Add(new XmlNodeConverter()); - - _settings.NullValueHandling = NullValueHandling.Include; - _settings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; - _settings.TypeNameHandling = TypeNameHandling.Objects; - _settings.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor; + return JsonConvert.SerializeObject(input); } - #region Implementation of ISerializer - - /// - /// Deserialize input stream to object - /// - /// - /// - /// - public object FromStream(Stream input, Type outputType) + public T Deserialize(string input) { - byte[] bytes = new byte[input.Length]; - input.Position = 0; - input.Read(bytes, 0, (int)input.Length); - string s = Encoding.UTF8.GetString(bytes); - - return JsonConvert.DeserializeObject(s, outputType, _settings); + return JsonConvert.DeserializeObject(input); } - - /// - /// Serialize object to streamed result - /// - /// - /// - public IStreamedResult ToStream(object input) - { - string s = JsonConvert.SerializeObject(input, Formatting.None, _settings); - byte[] bytes = Encoding.UTF8.GetBytes(s); - MemoryStream ms = new MemoryStream(bytes); - - return new StreamedResult(ms, true); - } - - #endregion } } diff --git a/src/Umbraco.Core/Serialization/SerializationExtensions.cs b/src/Umbraco.Core/Serialization/SerializationExtensions.cs deleted file mode 100644 index c88641a337..0000000000 --- a/src/Umbraco.Core/Serialization/SerializationExtensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.IO; -using System.Text; - -namespace Umbraco.Core.Serialization -{ - public static class SerializationExtensions - { - public static T FromJson(this AbstractSerializationService service, string json, string intent = null) - { - if (string.IsNullOrWhiteSpace(json)) return default(T); - return (T)service.FromJson(json, typeof(T), intent); - } - - public static T FromJson(this ISerializer serializer, string json, string intent = null) - { - if (string.IsNullOrWhiteSpace(json)) return default(T); - return (T)serializer.FromJson(json, typeof(T)); - } - - public static object FromJson(this ISerializer serializer, string json, Type outputType) - { - if (string.IsNullOrWhiteSpace(json)) return outputType.GetDefaultValue(); - var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); - return serializer.FromStream(stream, outputType); - } - - public static object FromJson(this AbstractSerializationService service, string json, Type outputType, string intent = null) - { - if (string.IsNullOrWhiteSpace(json)) return outputType.GetDefaultValue(); - var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); - return service.FromStream(stream, outputType, intent); - } - - public static string ToJson(this AbstractSerializationService service, object input, string intent = null) - { - return StreamResultExtensions.ToJsonString(service.ToStream(input, intent).ResultStream); - } - } -} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index d41240c586..085a830fbf 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -124,34 +124,17 @@ Constants.cs --> - - - - - - - - - - + + + + - - - - - - - - - - - @@ -309,7 +292,7 @@ - + @@ -1090,7 +1073,6 @@ - diff --git a/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs b/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs index 4161f576c9..74aba2b824 100644 --- a/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs @@ -29,8 +29,7 @@ namespace Umbraco.Tests.Cache { var isCached = false; var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback(() => { isCached = true; @@ -59,9 +58,8 @@ namespace Umbraco.Tests.Cache { var cached = new List(); var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string cacheKey, Func o, TimeSpan? t, bool b, string[] s) => { cached.Add(cacheKey); }); diff --git a/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs b/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs index a4fbdf2224..027f6d2d69 100644 --- a/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs @@ -38,8 +38,7 @@ namespace Umbraco.Tests.Cache var isCached = false; var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback(() => { isCached = true; @@ -79,9 +78,8 @@ namespace Umbraco.Tests.Cache IList list = null; var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string cacheKey, Func o, TimeSpan? t, bool b, string[] s) => { cached.Add(cacheKey); @@ -122,9 +120,8 @@ namespace Umbraco.Tests.Cache IList list = null; var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string cacheKey, Func o, TimeSpan? t, bool b, string[] s) => { cached.Add(cacheKey); diff --git a/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs b/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs index 0be38d2c55..042830e059 100644 --- a/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs +++ b/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs @@ -46,7 +46,7 @@ namespace Umbraco.Tests.Cache protected override int GetTotalItemCount { - get { return _appCache.Items.Count; } + get { return _appCache.Count; } } } } diff --git a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs index 2525eab45b..335335e391 100644 --- a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs @@ -29,9 +29,8 @@ namespace Umbraco.Tests.Cache { var cached = new List(); var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string cacheKey, Func o, TimeSpan? t, bool b, string[] s) => { cached.Add(cacheKey); }); @@ -53,8 +52,7 @@ namespace Umbraco.Tests.Cache { var isCached = false; var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback(() => { isCached = true; diff --git a/src/Umbraco.Tests/Models/ContentTests.cs b/src/Umbraco.Tests/Models/ContentTests.cs index 3116087669..524d6fe5b1 100644 --- a/src/Umbraco.Tests/Models/ContentTests.cs +++ b/src/Umbraco.Tests/Models/ContentTests.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Linq; using System.Threading; using Moq; +using Newtonsoft.Json; using Umbraco.Core; using NUnit.Framework; using Umbraco.Core.Cache; @@ -476,8 +477,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - // Arrange var contentType = MockedContentTypes.CreateTextPageContentType(); contentType.Id = 99; @@ -503,8 +502,7 @@ namespace Umbraco.Tests.Models content.UpdateDate = DateTime.Now; content.WriterId = 23; - var result = ss.ToStream(content); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(content); Debug.Print(json); } diff --git a/src/Umbraco.Tests/Models/ContentTypeTests.cs b/src/Umbraco.Tests/Models/ContentTypeTests.cs index 9c3b976bf3..7d4b1cdcc7 100644 --- a/src/Umbraco.Tests/Models/ContentTypeTests.cs +++ b/src/Umbraco.Tests/Models/ContentTypeTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -287,8 +288,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Content_Type_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - // Arrange var contentType = MockedContentTypes.CreateTextPageContentType(); contentType.Id = 99; @@ -318,8 +317,7 @@ namespace Umbraco.Tests.Models contentType.Trashed = false; contentType.UpdateDate = DateTime.Now; - var result = ss.ToStream(contentType); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(contentType); Debug.Print(json); } @@ -391,8 +389,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Media_Type_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - // Arrange var contentType = MockedContentTypes.CreateImageMediaType(); contentType.Id = 99; @@ -416,8 +412,7 @@ namespace Umbraco.Tests.Models contentType.Trashed = false; contentType.UpdateDate = DateTime.Now; - var result = ss.ToStream(contentType); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(contentType); Debug.Print(json); } @@ -492,8 +487,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Member_Type_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - // Arrange var contentType = MockedContentTypes.CreateSimpleMemberType(); contentType.Id = 99; @@ -519,8 +512,7 @@ namespace Umbraco.Tests.Models contentType.SetMemberCanEditProperty("title", true); contentType.SetMemberCanViewProperty("bodyText", true); - var result = ss.ToStream(contentType); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(contentType); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/DataTypeTests.cs b/src/Umbraco.Tests/Models/DataTypeTests.cs index 6a943c9695..50d9f6e21b 100644 --- a/src/Umbraco.Tests/Models/DataTypeTests.cs +++ b/src/Umbraco.Tests/Models/DataTypeTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using Moq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -58,8 +59,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var dtd = new DataType(new VoidEditor(Mock.Of()), 9) { CreateDate = DateTime.Now, @@ -76,8 +75,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(dtd); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(dtd); Debug.Print(json); } diff --git a/src/Umbraco.Tests/Models/DictionaryItemTests.cs b/src/Umbraco.Tests/Models/DictionaryItemTests.cs index 924216f7d3..70d1efda87 100644 --- a/src/Umbraco.Tests/Models/DictionaryItemTests.cs +++ b/src/Umbraco.Tests/Models/DictionaryItemTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -84,8 +85,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new DictionaryItem("blah") { CreateDate = DateTime.Now, @@ -129,8 +128,8 @@ namespace Umbraco.Tests.Models } }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs b/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs index d7fcea71f0..7999537e7a 100644 --- a/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs +++ b/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -55,8 +56,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new DictionaryTranslation(new Language("en-AU") { CreateDate = DateTime.Now, @@ -73,8 +72,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/LanguageTests.cs b/src/Umbraco.Tests/Models/LanguageTests.cs index 5f8d858007..8e41b28b08 100644 --- a/src/Umbraco.Tests/Models/LanguageTests.cs +++ b/src/Umbraco.Tests/Models/LanguageTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -43,8 +44,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new Language("en-AU") { CreateDate = DateTime.Now, @@ -55,8 +54,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/LightEntityTest.cs b/src/Umbraco.Tests/Models/LightEntityTest.cs index 41ce830cff..43513e2d3e 100644 --- a/src/Umbraco.Tests/Models/LightEntityTest.cs +++ b/src/Umbraco.Tests/Models/LightEntityTest.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; @@ -13,8 +14,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new DocumentEntitySlim() { Id = 3, @@ -38,8 +37,7 @@ namespace Umbraco.Tests.Models item.AdditionalData.Add("test1", 3); item.AdditionalData.Add("test2", "valuie"); - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); // FIXME: compare with v7 } } diff --git a/src/Umbraco.Tests/Models/MemberGroupTests.cs b/src/Umbraco.Tests/Models/MemberGroupTests.cs index fc76980890..c3cf1c8c76 100644 --- a/src/Umbraco.Tests/Models/MemberGroupTests.cs +++ b/src/Umbraco.Tests/Models/MemberGroupTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -51,8 +52,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var group = new MemberGroup() { CreateDate = DateTime.Now, @@ -65,8 +64,7 @@ namespace Umbraco.Tests.Models group.AdditionalData.Add("test1", 123); group.AdditionalData.Add("test2", "hello"); - var result = ss.ToStream(group); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(group); Debug.Print(json); } diff --git a/src/Umbraco.Tests/Models/MemberTests.cs b/src/Umbraco.Tests/Models/MemberTests.cs index 5e92ad7ccf..4680ee67f5 100644 --- a/src/Umbraco.Tests/Models/MemberTests.cs +++ b/src/Umbraco.Tests/Models/MemberTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Composing; using Umbraco.Core.Models; @@ -113,8 +114,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var memberType = MockedContentTypes.CreateSimpleMemberType("memberType", "Member Type"); memberType.Id = 99; var member = MockedMember.CreateSimpleMember(memberType, "Name", "email@email.com", "pass", "user", Guid.NewGuid()); @@ -147,8 +146,7 @@ namespace Umbraco.Tests.Models member.AdditionalData.Add("test1", 123); member.AdditionalData.Add("test2", "hello"); - var result = ss.ToStream(member); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(member); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/PropertyGroupTests.cs b/src/Umbraco.Tests/Models/PropertyGroupTests.cs index 0552acf930..a68b526951 100644 --- a/src/Umbraco.Tests/Models/PropertyGroupTests.cs +++ b/src/Umbraco.Tests/Models/PropertyGroupTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -88,8 +89,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var pg = new PropertyGroup( new PropertyTypeCollection(false, new[] { @@ -135,8 +134,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(pg); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(pg); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/PropertyTypeTests.cs b/src/Umbraco.Tests/Models/PropertyTypeTests.cs index 568d12264d..1bc99162af 100644 --- a/src/Umbraco.Tests/Models/PropertyTypeTests.cs +++ b/src/Umbraco.Tests/Models/PropertyTypeTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -60,8 +61,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var pt = new PropertyType("TestPropertyEditor", ValueStorageType.Nvarchar, "test") { Id = 3, @@ -79,8 +78,7 @@ namespace Umbraco.Tests.Models ValueStorageType = ValueStorageType.Nvarchar }; - var result = ss.ToStream(pt); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(pt); Debug.Print(json); } diff --git a/src/Umbraco.Tests/Models/RelationTests.cs b/src/Umbraco.Tests/Models/RelationTests.cs index c62dcdc6eb..1e0c7ccb59 100644 --- a/src/Umbraco.Tests/Models/RelationTests.cs +++ b/src/Umbraco.Tests/Models/RelationTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -50,8 +51,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new Relation(9, 8, new RelationType(Guid.NewGuid(), Guid.NewGuid(), "test") { Id = 66 @@ -64,8 +63,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/RelationTypeTests.cs b/src/Umbraco.Tests/Models/RelationTypeTests.cs index 9d8fdcdf25..765ac26f7f 100644 --- a/src/Umbraco.Tests/Models/RelationTypeTests.cs +++ b/src/Umbraco.Tests/Models/RelationTypeTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -46,8 +47,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new RelationType(Guid.NewGuid(), Guid.NewGuid(), "test") { Id = 66, @@ -58,8 +57,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/StylesheetTests.cs b/src/Umbraco.Tests/Models/StylesheetTests.cs index b8990f6d29..f76e0083dc 100644 --- a/src/Umbraco.Tests/Models/StylesheetTests.cs +++ b/src/Umbraco.Tests/Models/StylesheetTests.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -101,8 +102,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var stylesheet = new Stylesheet("/css/styles.css"); stylesheet.Content = @"@media screen and (min-width: 600px) and (min-width: 900px) { .class { @@ -110,8 +109,7 @@ namespace Umbraco.Tests.Models } }"; - var result = ss.ToStream(stylesheet); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(stylesheet); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/TemplateTests.cs b/src/Umbraco.Tests/Models/TemplateTests.cs index 0813bc9f4e..b73b8d9fa0 100644 --- a/src/Umbraco.Tests/Models/TemplateTests.cs +++ b/src/Umbraco.Tests/Models/TemplateTests.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Linq; using System.Reflection; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -61,8 +62,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new Template("Test", "test") { Id = 3, @@ -74,8 +73,7 @@ namespace Umbraco.Tests.Models MasterTemplateId = new Lazy(() => 88) }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } diff --git a/src/Umbraco.Tests/Models/UserTests.cs b/src/Umbraco.Tests/Models/UserTests.cs index 797b79381a..705301b9ed 100644 --- a/src/Umbraco.Tests/Models/UserTests.cs +++ b/src/Umbraco.Tests/Models/UserTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Composing; using Umbraco.Core.Models.Membership; @@ -68,8 +69,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new User { Id = 3, @@ -97,8 +96,7 @@ namespace Umbraco.Tests.Models Username = "username" }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Persistence/Repositories/ServerRegistrationRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ServerRegistrationRepositoryTest.cs index e2fc4b4705..b84a79b3d1 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ServerRegistrationRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ServerRegistrationRepositoryTest.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Persistence.Repositories { base.SetUp(); - _appCaches = new AppCaches(); + _appCaches = AppCaches.Disabled; CreateTestData(); } diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index 340f24ef28..ac402ad77d 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -146,7 +146,7 @@ namespace Umbraco.Tests.Routing var handler = new RenderRouteHandler(umbracoContext, new TestControllerFactory(umbracoContextAccessor, Mock.Of(), context => { var membershipHelper = new MembershipHelper( - umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); + umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), AppCaches.Disabled, Mock.Of()); return new CustomDocumentController(Factory.GetInstance(), umbracoContextAccessor, Factory.GetInstance(), diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index d0258a100f..1f1500137f 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -59,7 +59,7 @@ namespace Umbraco.Tests.Runtimes var logger = new ConsoleLogger(); var profiler = new LogProfiler(logger); var profilingLogger = new ProfilingLogger(logger, profiler); - var appCaches = new AppCaches(); // FIXME: has HttpRuntime stuff? + var appCaches = AppCaches.Disabled; var databaseFactory = new UmbracoDatabaseFactory(logger, new Lazy(() => factory.GetInstance())); var typeLoader = new TypeLoader(appCaches.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger); var mainDom = new SimpleMainDom(); diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs index e52d338ca6..4b41d4fbc4 100644 --- a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs +++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs @@ -150,7 +150,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting urlHelper.Setup(provider => provider.GetUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(UrlInfo.Url("/hello/world/1234")); - var membershipHelper = new MembershipHelper(umbCtx.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); + var membershipHelper = new MembershipHelper(umbCtx.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), AppCaches.Disabled, Mock.Of()); var umbHelper = new UmbracoHelper(Mock.Of(), Mock.Of(), diff --git a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs index ee91427a63..7096158aa8 100644 --- a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs +++ b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs @@ -70,7 +70,7 @@ namespace Umbraco.Tests.Testing.TestingTests Mock.Of(), Mock.Of(), Mock.Of(), - new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of())); + new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), AppCaches.Disabled, Mock.Of())); Assert.Pass(); } @@ -98,7 +98,7 @@ namespace Umbraco.Tests.Testing.TestingTests { var umbracoContext = TestObjects.GetUmbracoContextMock(); - var membershipHelper = new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); + var membershipHelper = new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), AppCaches.Disabled, Mock.Of()); var umbracoHelper = new UmbracoHelper(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), membershipHelper); var umbracoMapper = new UmbracoMapper(new MapDefinitionCollection(new[] { Mock.Of() })); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 7e72a5aefb..b9fd0f6640 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -37,6 +37,7 @@ using Umbraco.Web.Routing; using Umbraco.Web.Trees; using Umbraco.Core.Composing.CompositionExtensions; using Umbraco.Core.Mapping; +using Umbraco.Core.Serialization; using Umbraco.Web.Composing.CompositionExtensions; using Umbraco.Web.Sections; using Current = Umbraco.Core.Composing.Current; @@ -327,6 +328,8 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(factory => ExamineManager.Instance); + Composition.RegisterUnique(); + // register filesystems Composition.RegisterUnique(factory => TestObjects.GetFileSystemsMock()); diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs index a9c405237b..f051d2eef4 100644 --- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs @@ -120,7 +120,7 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), Mock.Of(), Mock.Of(query => query.Content(2) == content.Object), - new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of())); + new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), AppCaches.Disabled, Mock.Of())); var ctrl = new TestSurfaceController(umbracoContextAccessor, helper); var result = ctrl.GetContent(2) as PublishedContentResult; @@ -178,7 +178,7 @@ namespace Umbraco.Tests.Web.Mvc public class TestSurfaceController : SurfaceController { public TestSurfaceController(IUmbracoContextAccessor umbracoContextAccessor, UmbracoHelper helper = null) - : base(umbracoContextAccessor, null, ServiceContext.CreatePartial(), Mock.Of(), null, null, helper) + : base(umbracoContextAccessor, null, ServiceContext.CreatePartial(), AppCaches.Disabled, null, null, helper) { } diff --git a/src/Umbraco.Web/Cache/ContentCacheRefresher.cs b/src/Umbraco.Web/Cache/ContentCacheRefresher.cs index d9a6518493..0422d3c674 100644 --- a/src/Umbraco.Web/Cache/ContentCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ContentCacheRefresher.cs @@ -7,6 +7,7 @@ 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; @@ -20,8 +21,8 @@ namespace Umbraco.Web.Cache private readonly IdkMap _idkMap; private readonly IDomainService _domainService; - public ContentCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap, IDomainService domainService) - : base(appCaches) + public ContentCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap, IDomainService domainService) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _idkMap = idkMap; diff --git a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs index 63cfe0df9e..655baf18bf 100644 --- a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs @@ -5,6 +5,7 @@ using Umbraco.Core.Cache; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Persistence.Repositories; +using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Services.Changes; using Umbraco.Web.PublishedCache; @@ -18,8 +19,8 @@ namespace Umbraco.Web.Cache private readonly IContentTypeCommonRepository _contentTypeCommonRepository; private readonly IdkMap _idkMap; - public ContentTypeCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) - : base(appCaches) + public ContentTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; diff --git a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs index c9caf5aaa7..3c83ff3027 100644 --- a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs @@ -4,6 +4,7 @@ using Umbraco.Core.Cache; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors.ValueConverters; +using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Web.PublishedCache; @@ -16,8 +17,8 @@ namespace Umbraco.Web.Cache private readonly IPublishedModelFactory _publishedModelFactory; private readonly IdkMap _idkMap; - public DataTypeCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap) - : base(appCaches) + public DataTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; diff --git a/src/Umbraco.Web/Cache/DomainCacheRefresher.cs b/src/Umbraco.Web/Cache/DomainCacheRefresher.cs index 4ffe4e2717..7958728765 100644 --- a/src/Umbraco.Web/Cache/DomainCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/DomainCacheRefresher.cs @@ -1,6 +1,7 @@ using System; using Umbraco.Core.Cache; using Umbraco.Core.Models; +using Umbraco.Core.Serialization; using Umbraco.Core.Services.Changes; using Umbraco.Web.PublishedCache; @@ -10,8 +11,8 @@ namespace Umbraco.Web.Cache { private readonly IPublishedSnapshotService _publishedSnapshotService; - public DomainCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService) - : base(appCaches) + public DomainCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; } diff --git a/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs b/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs index b1fc0a9e55..dfb85aad6a 100644 --- a/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs @@ -2,6 +2,7 @@ using System.Linq; using Umbraco.Core.Cache; using Umbraco.Core.Models; +using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Services.Changes; using Umbraco.Web.PublishedCache; @@ -13,8 +14,8 @@ namespace Umbraco.Web.Cache //CacheRefresherBase { - public LanguageCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService) - : base(appCaches) + public LanguageCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; } diff --git a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs index 1f54b62c5b..8da643c279 100644 --- a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs @@ -6,6 +6,7 @@ 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; @@ -18,8 +19,8 @@ namespace Umbraco.Web.Cache private readonly IPublishedSnapshotService _publishedSnapshotService; private readonly IdkMap _idkMap; - public MediaCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap) - : base(appCaches) + public MediaCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _idkMap = idkMap; diff --git a/src/Umbraco.Web/CacheHelperExtensions.cs b/src/Umbraco.Web/CacheHelperExtensions.cs index ae8df63415..615e6a3982 100644 --- a/src/Umbraco.Web/CacheHelperExtensions.cs +++ b/src/Umbraco.Web/CacheHelperExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Web; -using System.Web.Caching; using System.Web.Mvc; using System.Web.Mvc.Html; using Umbraco.Core.Cache; @@ -46,7 +45,6 @@ namespace Umbraco.Web return appCaches.RuntimeCache.GetCacheItem( PartialViewCacheKey + cacheKey, () => htmlHelper.Partial(partialViewName, model, viewData), - priority: CacheItemPriority.NotRemovable, //not removable, the same as macros (apparently issue #27610) timeout: new TimeSpan(0, 0, 0, cachedSeconds)); } diff --git a/src/Umbraco.Web/Macros/MacroRenderer.cs b/src/Umbraco.Web/Macros/MacroRenderer.cs index 3368def084..038a4d2431 100755 --- a/src/Umbraco.Web/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web/Macros/MacroRenderer.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using System.Web.Caching; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration.UmbracoSettings; @@ -139,8 +138,7 @@ namespace Umbraco.Web.Macros cache.Insert( CacheKeys.MacroContentCacheKey + model.CacheIdentifier, () => macroContent, - new TimeSpan(0, 0, model.CacheDuration), - priority: CacheItemPriority.NotRemovable + new TimeSpan(0, 0, model.CacheDuration) ); _plogger.Debug("Macro content saved to cache '{MacroCacheId}'", model.CacheIdentifier);