Merge remote-tracking branch 'origin/netcore/dev' into netcore/dev

This commit is contained in:
Bjarke Berg
2019-11-07 13:02:56 +01:00
74 changed files with 263 additions and 614 deletions
@@ -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<T> 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<T>().Result;
}
@@ -28,11 +25,9 @@ namespace Umbraco.Core.Cache
Func<T> 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<T> GetCacheItemsByKeySearch<T>(this IAppCache provider, string keyStartsWith)
@@ -1,5 +1,4 @@
using System;
using System.Web;
namespace Umbraco.Core.Cache
{
@@ -8,23 +7,6 @@ namespace Umbraco.Core.Cache
/// </summary>
public class AppCaches
{
/// <summary>
/// Initializes a new instance of the <see cref="AppCaches"/> for use in a web application.
/// </summary>
public AppCaches()
: this(HttpRuntime.Cache)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="AppCaches"/> for use in a web application.
/// </summary>
public AppCaches(System.Web.Caching.Cache cache)
: this(
new WebCachingAppCache(cache),
new HttpRequestAppCache(),
new IsolatedCaches(t => new ObjectCacheAppCache()))
{ }
/// <summary>
/// Initializes a new instance of the <see cref="AppCaches"/> with cache providers.
/// </summary>
@@ -17,24 +17,24 @@ namespace Umbraco.Core.Cache
/// <param name="cacheFactory"></param>
protected AppPolicedCacheDictionary(Func<TKey, IAppPolicyCache> cacheFactory)
{
CacheFactory = cacheFactory;
_cacheFactory = cacheFactory;
}
/// <summary>
/// Gets the internal cache factory, for tests only!
/// </summary>
internal readonly Func<TKey, IAppPolicyCache> CacheFactory;
private readonly Func<TKey, IAppPolicyCache> _cacheFactory;
/// <summary>
/// Gets or creates a cache.
/// </summary>
public IAppPolicyCache GetOrCreate(TKey key)
=> _caches.GetOrAdd(key, k => CacheFactory(k));
=> _caches.GetOrAdd(key, k => _cacheFactory(k));
/// <summary>
/// Tries to get a cache.
/// </summary>
public Attempt<IAppPolicyCache> Get(TKey key)
protected Attempt<IAppPolicyCache> Get(TKey key)
=> _caches.TryGetValue(key, out var cache) ? Attempt.Succeed(cache) : Attempt.Fail<IAppPolicyCache>();
/// <summary>
@@ -56,7 +56,7 @@ namespace Umbraco.Core.Cache
/// <summary>
/// Clears a cache.
/// </summary>
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();
}
}
}
}
@@ -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.
/// </summary>
internal class DeepCloneAppCache : IAppPolicyCache
public class DeepCloneAppCache : IAppPolicyCache
{
/// <summary>
/// Initializes a new instance of the <see cref="DeepCloneAppCache"/> class.
@@ -30,7 +29,7 @@ namespace Umbraco.Core.Cache
/// <summary>
/// Gets the inner cache.
/// </summary>
public IAppPolicyCache InnerCache { get; }
private IAppPolicyCache InnerCache { get; }
/// <inheritdoc />
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
}
/// <inheritdoc />
public object Get(string key, Func<object> factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null)
public object Get(string key, Func<object> 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);
}
/// <inheritdoc />
public void Insert(string key, Func<object> factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null)
public void Insert(string key, Func<object> 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);
}
/// <inheritdoc />
@@ -13,25 +13,27 @@ namespace Umbraco.Core.Cache
/// <summary>
/// Gets the internal items dictionary, for tests only!
/// </summary>
internal readonly ConcurrentDictionary<string, object> Items = new ConcurrentDictionary<string, object>();
private readonly ConcurrentDictionary<string, object> _items = new ConcurrentDictionary<string, object>();
public int Count => _items.Count;
/// <inheritdoc />
public virtual object Get(string key)
{
return Items.TryGetValue(key, out var value) ? value : null;
return _items.TryGetValue(key, out var value) ? value : null;
}
/// <inheritdoc />
public virtual object Get(string key, Func<object> factory)
{
return Items.GetOrAdd(key, _ => factory());
return _items.GetOrAdd(key, _ => factory());
}
/// <inheritdoc />
public virtual IEnumerable<object> SearchByKey(string keyStartsWith)
{
var items = new List<object>();
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<object>();
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
/// <inheritdoc />
public virtual void Clear()
{
Items.Clear();
_items.Clear();
}
/// <inheritdoc />
public virtual void Clear(string key)
{
Items.TryRemove(key, out _);
_items.TryRemove(key, out _);
}
/// <inheritdoc />
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));
}
/// <inheritdoc />
public virtual void ClearOfType<T>()
{
var typeOfT = typeof(T);
Items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT);
_items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT);
}
/// <inheritdoc />
public virtual void ClearOfType<T>(Func<string, T, bool> 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));
}
/// <inheritdoc />
public virtual void ClearByKey(string keyStartsWith)
{
Items.RemoveAll(kvp => kvp.Key.InvariantStartsWith(keyStartsWith));
_items.RemoveAll(kvp => kvp.Key.InvariantStartsWith(keyStartsWith));
}
/// <inheritdoc />
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));
}
}
}
@@ -1,5 +1,4 @@
using System;
using System.Web.Caching;
namespace Umbraco.Core.Cache
{
@@ -17,8 +16,6 @@ namespace Umbraco.Core.Cache
/// <param name="factory">A factory function that can create the item.</param>
/// <param name="timeout">An optional cache timeout.</param>
/// <param name="isSliding">An optional value indicating whether the cache timeout is sliding (default is false).</param>
/// <param name="priority">An optional cache priority (default is Normal).</param>
/// <param name="removedCallback">An optional callback to handle removals.</param>
/// <param name="dependentFiles">Files the cache entry depends on.</param>
/// <returns>The item.</returns>
object Get(
@@ -26,8 +23,6 @@ namespace Umbraco.Core.Cache
Func<object> factory,
TimeSpan? timeout,
bool isSliding = false,
CacheItemPriority priority = CacheItemPriority.Normal,
CacheItemRemovedCallback removedCallback = null,
string[] dependentFiles = null);
/// <summary>
@@ -37,16 +32,12 @@ namespace Umbraco.Core.Cache
/// <param name="factory">A factory function that can create the item.</param>
/// <param name="timeout">An optional cache timeout.</param>
/// <param name="isSliding">An optional value indicating whether the cache timeout is sliding (default is false).</param>
/// <param name="priority">An optional cache priority (default is Normal).</param>
/// <param name="removedCallback">An optional callback to handle removals.</param>
/// <param name="dependentFiles">Files the cache entry depends on.</param>
void Insert(
string key,
Func<object> factory,
TimeSpan? timeout = null,
bool isSliding = false,
CacheItemPriority priority = CacheItemPriority.Normal,
CacheItemRemovedCallback removedCallback = null,
string[] dependentFiles = null);
}
}
@@ -5,7 +5,7 @@ using Umbraco.Core.Scoping;
namespace Umbraco.Core.Cache
{
internal interface IRepositoryCachePolicy<TEntity, TId>
public interface IRepositoryCachePolicy<TEntity, TId>
where TEntity : class, IEntity
{
/// <summary>
@@ -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
}
/// <inheritdoc />
public object Get(string key, Func<object> factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null)
public object Get(string key, Func<object> factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null)
{
return factory();
}
/// <inheritdoc />
public void Insert(string key, Func<object> factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null)
public void Insert(string key, Func<object> factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null)
{ }
/// <inheritdoc />
@@ -5,7 +5,7 @@ using Umbraco.Core.Models.Entities;
namespace Umbraco.Core.Cache
{
internal class NoCacheRepositoryCachePolicy<TEntity, TId> : IRepositoryCachePolicy<TEntity, TId>
public class NoCacheRepositoryCachePolicy<TEntity, TId> : IRepositoryCachePolicy<TEntity, TId>
where TEntity : class, IEntity
{
private NoCacheRepositoryCachePolicy() { }
@@ -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<TInstanceType, TPayload> : JsonCacheRefresherBase<TInstanceType>, IPayloadCacheRefresher<TPayload>
where TInstanceType : class, ICacheRefresher
{
private readonly IJsonSerializer _serializer;
/// <summary>
/// Initializes a new instance of the <see cref="PayloadCacheRefresherBase{TInstanceType, TPayload}"/>.
/// </summary>
/// <param name="appCaches">A cache helper.</param>
protected PayloadCacheRefresherBase(AppCaches appCaches) : base(appCaches)
{ }
/// <param name="serializer"></param>
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
/// <returns>The deserialized object payload.</returns>
protected virtual TPayload[] Deserialize(string json)
{
return JsonConvert.DeserializeObject<TPayload[]>(json);
return _serializer.Deserialize<TPayload[]>(json);
}
#endregion
@@ -5,7 +5,7 @@ namespace Umbraco.Core.Cache
/// <summary>
/// Specifies how a repository cache policy should cache entities.
/// </summary>
internal class RepositoryCachePolicyOptions
public class RepositoryCachePolicyOptions
{
/// <summary>
/// Ctor - sets GetAllCacheValidateCount = true
@@ -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<object> GetSafeLazy(Func<object> 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<object>(() =>
{
try
{
return getCacheItem();
}
catch (Exception e)
{
return new ExceptionHolder(ExceptionDispatchInfo.Capture(e));
}
});
}
public static object GetSafeLazyValue(Lazy<object> 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<T> 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; }
}
}
}
@@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Umbraco.Core.Serialization
{
public abstract class AbstractSerializationService
{
/// <summary>
/// A sequence of <see cref="IFormatter" /> registered with this serialization service.
/// </summary>
public IEnumerable<IFormatter> Formatters { get; set; }
/// <summary>
/// Finds an <see cref="IFormatter" /> with a matching <paramref name="intent" /> , and deserializes the <see cref="Stream" /> <paramref
/// name="input" /> to an object graph.
/// </summary>
/// <param name="input"> </param>
/// <param name="outputType"> </param>
/// <param name="intent"> </param>
/// <returns> </returns>
public abstract object FromStream(Stream input, Type outputType, string intent = null);
/// <summary>
/// Finds an <see cref="IFormatter" /> with a matching <paramref name="intent" /> , and serializes the <paramref
/// name="input" /> object graph to an <see cref="IStreamedResult" /> .
/// </summary>
/// <param name="input"> </param>
/// <param name="intent"> </param>
/// <returns> </returns>
public abstract IStreamedResult ToStream(object input, string intent = 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
}
}
@@ -1,9 +0,0 @@
namespace Umbraco.Core.Serialization
{
public interface IFormatter
{
string Intent { get; }
ISerializer Serializer { get; }
}
}
@@ -0,0 +1,9 @@
namespace Umbraco.Core.Serialization
{
public interface IJsonSerializer
{
string Serialize(object input);
T Deserialize<T>(string input);
}
}
@@ -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);
}
}
@@ -1,10 +0,0 @@
using System.IO;
namespace Umbraco.Core.Serialization
{
public interface IStreamedResult
{
Stream ResultStream { get; }
bool Success { get; }
}
}
@@ -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
/// <summary>
/// Finds an <see cref="IFormatter" /> with a matching <paramref name="intent" /> , and deserializes the <see cref="Stream" /> <paramref
/// name="input" /> to an object graph.
/// </summary>
/// <param name="input"> </param>
/// <param name="outputType"> </param>
/// <param name="intent"> </param>
/// <returns> </returns>
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);
}
/// <summary>
/// Finds an <see cref="IFormatter" /> with a matching <paramref name="intent" /> , and serializes the <paramref
/// name="input" /> object graph to an <see cref="IStreamedResult" /> .
/// </summary>
/// <param name="input"> </param>
/// <param name="intent"> </param>
/// <returns> </returns>
public override IStreamedResult ToStream(object input, string intent = null)
{
return _serializer.ToStream(input);
}
#endregion
}
}
@@ -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);
}
}
}
@@ -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
}
}
@@ -6,4 +6,8 @@
<RootNamespace>Umbraco.Core</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.Caching" Version="4.6.0" />
</ItemGroup>
</Project>
@@ -17,7 +17,7 @@ namespace Umbraco.Core.Cache
/// <para>If options.GetAllCacheAllowZeroCount then a 'zero-count' array is cached when GetAll finds nothing.</para>
/// <para>If options.GetAllCacheValidateCount then we check against the db when getting many entities.</para>
/// </remarks>
internal class DefaultRepositoryCachePolicy<TEntity, TId> : RepositoryCachePolicyBase<TEntity, TId>
public class DefaultRepositoryCachePolicy<TEntity, TId> : RepositoryCachePolicyBase<TEntity, TId>
where TEntity : class, IEntity
{
private static readonly TEntity[] EmptyEntities = new TEntity[0]; // const
@@ -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
}
/// <inheritdoc />
public object Get(string cacheKey, Func<object> 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<object> 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
@@ -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
/// <inheritdoc />
@@ -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
}
/// <inheritdoc />
@@ -59,7 +55,7 @@ namespace Umbraco.Core.Cache
}
return entries
.Select(x => GetSafeLazyValue((Lazy<object>)x.Value)) // return exceptions as null
.Select(x => SafeLazy.GetSafeLazyValue((Lazy<object>)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<object>)x.Value)) // return exceptions as null
.Select(x => SafeLazy.GetSafeLazyValue((Lazy<object>)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<object> 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<object>) x.Value, true);
var value = SafeLazy.GetSafeLazyValue((Lazy<object>) 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<object>) x.Value, true);
var value = SafeLazy.GetSafeLazyValue((Lazy<object>) 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<object>) x.Value, true);
var value = SafeLazy.GetSafeLazyValue((Lazy<object>) 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<object> GetSafeLazy(Func<object> 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<object>(() =>
{
try
{
return getCacheItem();
}
catch (Exception e)
{
return new ExceptionHolder(ExceptionDispatchInfo.Capture(e));
}
});
}
protected internal static object GetSafeLazyValue(Lazy<object> 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<T> 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
}
@@ -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;
}
+15 -45
View File
@@ -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
}
/// <inheritdoc />
@@ -73,7 +71,7 @@ namespace Umbraco.Core.Cache
_locker.ExitReadLock();
}
return entries
.Select(x => FastDictionaryAppCacheBase.GetSafeLazyValue((Lazy<object>)x.Value)) // return exceptions as null
.Select(x => SafeLazy.GetSafeLazyValue((Lazy<object>)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<object>)x.Value)) // return exceptions as null
.Select(x => SafeLazy.GetSafeLazyValue((Lazy<object>)x.Value)) // return exceptions as null
.Where(x => x != null) // backward compat, don't store null values in the cache
.ToList();
}
/// <inheritdoc />
public object Get(string key, Func<object> factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null)
public object Get(string key, Func<object> 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<object>;
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;
}
/// <inheritdoc />
public void Insert(string key, Func<object> factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null)
public void Insert(string key, Func<object> factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null)
{
// NOTE - here also we must insert a Lazy<object> 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<object> 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<object>)x.Value, true);
var value = SafeLazy.GetSafeLazyValue((Lazy<object>)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<object> 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<object>)x.Value, true);
var value = SafeLazy.GetSafeLazyValue((Lazy<object>)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<object> 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<object>)x.Value, true);
var value = SafeLazy.GetSafeLazyValue((Lazy<object>)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;
}
}
@@ -10,7 +10,7 @@ namespace Umbraco.Core.Cache
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <typeparam name="TId">The type of the identifier.</typeparam>
internal abstract class RepositoryCachePolicyBase<TEntity, TId> : IRepositoryCachePolicy<TEntity, TId>
public abstract class RepositoryCachePolicyBase<TEntity, TId> : IRepositoryCachePolicy<TEntity, TId>
where TEntity : class, IEntity
{
private readonly IAppPolicyCache _globalCache;
+13 -13
View File
@@ -35,25 +35,25 @@ namespace Umbraco.Core.Cache
}
/// <inheritdoc />
public object Get(string key, Func<object> factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null)
public object Get(string key, Func<object> 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);
}
/// <inheritdoc />
public void Insert(string key, Func<object> factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null)
public void Insert(string key, Func<object> 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<object> factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, CacheDependency dependency = null)
private object GetImpl(string key, Func<object> 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<object> getCacheItem, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, CacheDependency dependency = null)
private void InsertImpl(string cacheKey, Func<object> getCacheItem, TimeSpan? timeout = null, bool isSliding = false, CacheDependency dependency = null)
{
// NOTE - here also we must insert a Lazy<object> 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
{
@@ -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<IScopeProvider>(f => f.GetInstance<ScopeProvider>());
composition.RegisterUnique<IScopeAccessor>(f => f.GetInstance<ScopeProvider>());
composition.RegisterUnique<IJsonSerializer, JsonNetSerializer>();
// register database builder
// *not* a singleton, don't want to keep it around
composition.Register<DatabaseBuilder>();
@@ -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
/// <summary>
/// Deserialize input stream to object
/// </summary>
/// <param name="input"></param>
/// <param name="outputType"></param>
/// <returns></returns>
public object FromStream(Stream input, Type outputType)
public T Deserialize<T>(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<T>(input);
}
/// <summary>
/// Serialize object to streamed result
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
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
}
}
@@ -1,40 +0,0 @@
using System;
using System.IO;
using System.Text;
namespace Umbraco.Core.Serialization
{
public static class SerializationExtensions
{
public static T FromJson<T>(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<T>(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);
}
}
}
+5 -23
View File
@@ -124,34 +124,17 @@
<DependentUpon>Constants.cs</DependentUpon>
</Compile>
-->
<Compile Include="Cache\AppPolicedCacheDictionary.cs" />
<Compile Include="Compose\AuditEventsComponent.cs" />
<Compile Include="Cache\AppCaches.cs" />
<Compile Include="Cache\AppCacheExtensions.cs" />
<Compile Include="Cache\CacheRefresherBase.cs" />
<Compile Include="Cache\CacheRefresherCollection.cs" />
<Compile Include="Cache\CacheRefresherCollectionBuilder.cs" />
<Compile Include="Cache\CacheRefresherEventArgs.cs" />
<Compile Include="Cache\DeepCloneAppCache.cs" />
<Compile Include="Cache\DefaultRepositoryCachePolicy.cs" />
<Compile Include="Cache\FastDictionaryAppCache.cs" />
<Compile Include="Cache\FastDictionaryAppCacheBase.cs" />
<Compile Include="Cache\ObjectCacheAppCache.cs" />
<Compile Include="Compose\AuditEventsComponent.cs" />
<Compile Include="Cache\CacheRefresherCollectionBuilder.cs" />
<Compile Include="Cache\FastDictionaryAppCache.cs" />
<Compile Include="Cache\FullDataSetRepositoryCachePolicy.cs" />
<Compile Include="Cache\HttpRequestAppCache.cs" />
<Compile Include="Cache\WebCachingAppCache.cs" />
<Compile Include="Cache\IRepositoryCachePolicy.cs" />
<Compile Include="Cache\IAppPolicyCache.cs" />
<Compile Include="Cache\IsolatedCaches.cs" />
<Compile Include="Cache\JsonCacheRefresherBase.cs" />
<Compile Include="Cache\NoCacheRepositoryCachePolicy.cs" />
<Compile Include="Cache\NoAppCache.cs" />
<Compile Include="Cache\ObjectCacheAppCache.cs" />
<Compile Include="Cache\PayloadCacheRefresherBase.cs" />
<Compile Include="Cache\RepositoryCachePolicyBase.cs" />
<Compile Include="Cache\RepositoryCachePolicyOptions.cs" />
<Compile Include="Cache\SingleItemsOnlyRepositoryCachePolicy.cs" />
<Compile Include="Cache\DictionaryAppCache.cs" />
<Compile Include="Cache\TypedCacheRefresherBase.cs" />
<Compile Include="Compose\AuditEventsComposer.cs" />
<Compile Include="Composing\ComponentComposer.cs" />
<Compile Include="Composing\ComposeAfterAttribute.cs" />
@@ -309,7 +292,7 @@
<Compile Include="PropertyEditors\PropertyValueConverterCollectionBuilder.cs" />
<Compile Include="PropertyEditors\VoidEditor.cs" />
<Compile Include="PublishedModelFactoryExtensions.cs" />
<Compile Include="Serialization\SerializationExtensions.cs" />
<Compile Include="Serialization\JsonNetSerializer.cs" />
<Compile Include="Services\Changes\ContentTypeChange.cs" />
<Compile Include="Services\Changes\ContentTypeChangeExtensions.cs" />
<Compile Include="Services\Changes\TreeChange.cs" />
@@ -1090,7 +1073,6 @@
<Compile Include="Serialization\CaseInsensitiveDictionaryConverter.cs" />
<Compile Include="Serialization\ForceInt32Converter.cs" />
<Compile Include="Serialization\JsonReadConverter.cs" />
<Compile Include="Serialization\JsonNetSerializer.cs" />
<Compile Include="Serialization\JsonToStringConverter.cs" />
<Compile Include="Serialization\KnownTypeUdiJsonConverter.cs" />
<Compile Include="Serialization\NoTypeConverterJsonConverter.cs" />
@@ -29,8 +29,7 @@ namespace Umbraco.Tests.Cache
{
var isCached = false;
var cache = new Mock<IAppPolicyCache>();
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(), It.IsAny<string[]>()))
.Callback(() =>
{
isCached = true;
@@ -59,9 +58,8 @@ namespace Umbraco.Tests.Cache
{
var cached = new List<string>();
var cache = new Mock<IAppPolicyCache>();
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) =>
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> o, TimeSpan? t, bool b, string[] s) =>
{
cached.Add(cacheKey);
});
@@ -38,8 +38,7 @@ namespace Umbraco.Tests.Cache
var isCached = false;
var cache = new Mock<IAppPolicyCache>();
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(), It.IsAny<string[]>()))
.Callback(() =>
{
isCached = true;
@@ -79,9 +78,8 @@ namespace Umbraco.Tests.Cache
IList list = null;
var cache = new Mock<IAppPolicyCache>();
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) =>
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> 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<IAppPolicyCache>();
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) =>
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> o, TimeSpan? t, bool b, string[] s) =>
{
cached.Add(cacheKey);
@@ -46,7 +46,7 @@ namespace Umbraco.Tests.Cache
protected override int GetTotalItemCount
{
get { return _appCache.Items.Count; }
get { return _appCache.Count; }
}
}
}
@@ -29,9 +29,8 @@ namespace Umbraco.Tests.Cache
{
var cached = new List<string>();
var cache = new Mock<IAppPolicyCache>();
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) =>
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> 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<IAppPolicyCache>();
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
cache.Setup(x => x.Insert(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(), It.IsAny<string[]>()))
.Callback(() =>
{
isCached = true;
+2 -4
View File
@@ -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);
}
+4 -12
View File
@@ -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);
}
}
+2 -4
View File
@@ -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<ILogger>()), 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);
}
@@ -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);
}
}
@@ -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);
}
}
+2 -4
View File
@@ -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);
}
}
+2 -4
View File
@@ -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
}
}
+2 -4
View File
@@ -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);
}
+2 -4
View File
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
+2 -4
View File
@@ -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);
}
}
@@ -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);
}
}
+2 -4
View File
@@ -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);
}
}
+2 -4
View File
@@ -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<int>(() => 88)
};
var result = ss.ToStream(item);
var json = result.ResultStream.ToJsonString();
var json = JsonConvert.SerializeObject(item);
Debug.Print(json);
}
+2 -4
View File
@@ -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);
}
}
@@ -22,7 +22,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
base.SetUp();
_appCaches = new AppCaches();
_appCaches = AppCaches.Disabled;
CreateTestData();
}
@@ -146,7 +146,7 @@ namespace Umbraco.Tests.Routing
var handler = new RenderRouteHandler(umbracoContext, new TestControllerFactory(umbracoContextAccessor, Mock.Of<ILogger>(), context =>
{
var membershipHelper = new MembershipHelper(
umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), Mock.Of<AppCaches>(), Mock.Of<ILogger>());
umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>());
return new CustomDocumentController(Factory.GetInstance<IGlobalSettings>(),
umbracoContextAccessor,
Factory.GetInstance<ServiceContext>(),
@@ -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<IMapperCollection>(() => factory.GetInstance<IMapperCollection>()));
var typeLoader = new TypeLoader(appCaches.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger);
var mainDom = new SimpleMainDom();
@@ -150,7 +150,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
urlHelper.Setup(provider => provider.GetUrl(It.IsAny<UmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
.Returns(UrlInfo.Url("/hello/world/1234"));
var membershipHelper = new MembershipHelper(umbCtx.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), Mock.Of<AppCaches>(), Mock.Of<ILogger>());
var membershipHelper = new MembershipHelper(umbCtx.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>());
var umbHelper = new UmbracoHelper(Mock.Of<IPublishedContent>(),
Mock.Of<ITagQuery>(),
@@ -70,7 +70,7 @@ namespace Umbraco.Tests.Testing.TestingTests
Mock.Of<ICultureDictionaryFactory>(),
Mock.Of<IUmbracoComponentRenderer>(),
Mock.Of<IPublishedContentQuery>(),
new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), Mock.Of<AppCaches>(), Mock.Of<ILogger>()));
new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>()));
Assert.Pass();
}
@@ -98,7 +98,7 @@ namespace Umbraco.Tests.Testing.TestingTests
{
var umbracoContext = TestObjects.GetUmbracoContextMock();
var membershipHelper = new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), Mock.Of<AppCaches>(), Mock.Of<ILogger>());
var membershipHelper = new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>());
var umbracoHelper = new UmbracoHelper(Mock.Of<IPublishedContent>(), Mock.Of<ITagQuery>(), Mock.Of<ICultureDictionaryFactory>(), Mock.Of<IUmbracoComponentRenderer>(), Mock.Of<IPublishedContentQuery>(), membershipHelper);
var umbracoMapper = new UmbracoMapper(new MapDefinitionCollection(new[] { Mock.Of<IMapDefinition>() }));
@@ -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<IExamineManager>(factory => ExamineManager.Instance);
Composition.RegisterUnique<IJsonSerializer, JsonNetSerializer>();
// register filesystems
Composition.RegisterUnique(factory => TestObjects.GetFileSystemsMock());
@@ -120,7 +120,7 @@ namespace Umbraco.Tests.Web.Mvc
Mock.Of<ICultureDictionaryFactory>(),
Mock.Of<IUmbracoComponentRenderer>(),
Mock.Of<IPublishedContentQuery>(query => query.Content(2) == content.Object),
new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), Mock.Of<AppCaches>(), Mock.Of<ILogger>()));
new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>()));
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<AppCaches>(), null, null, helper)
: base(umbracoContextAccessor, null, ServiceContext.CreatePartial(), AppCaches.Disabled, null, null, helper)
{
}
@@ -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;
@@ -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;
@@ -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;
@@ -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;
}
@@ -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<LanguageCacheRefresher>
{
public LanguageCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService)
: base(appCaches)
public LanguageCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService)
: base(appCaches, serializer)
{
_publishedSnapshotService = publishedSnapshotService;
}
+3 -2
View File
@@ -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;
-2
View File
@@ -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<IHtmlString>(
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));
}
+1 -3
View File
@@ -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<MacroRenderer>("Macro content saved to cache '{MacroCacheId}'", model.CacheIdentifier);