diff --git a/src/Umbraco.Core/Cache/DictionaryCacheProviderBase.cs b/src/Umbraco.Core/Cache/DictionaryCacheProviderBase.cs index a2bcaee9c9..a6666d4e76 100644 --- a/src/Umbraco.Core/Cache/DictionaryCacheProviderBase.cs +++ b/src/Umbraco.Core/Cache/DictionaryCacheProviderBase.cs @@ -134,7 +134,15 @@ namespace Umbraco.Core.Cache // compare on exact type, don't use "is" // get non-created as NonCreatedValue & exceptions as null var value = GetSafeLazyValue((Lazy)x.Value, true); - return value == null || value.GetType() == typeOfT; + + //TODO: waiting on a response for this comment: https://github.com/umbraco/Umbraco-CMS/commit/c2db7b2b9b78847a828512818e79492ecc24ac7c#commitcomment-9492329 + // until then we will check if 'T' is an interface and if so we will use the 'is' clause, + // otherwise we do an exact match. + + return value == null || + (typeOfT.IsInterface + ? (value is T) + : value.GetType() == typeOfT); }) .ToArray()) RemoveEntry((string) entry.Key); @@ -156,9 +164,14 @@ namespace Umbraco.Core.Cache // get non-created as NonCreatedValue & exceptions as null var value = GetSafeLazyValue((Lazy)x.Value, true); if (value == null) return true; - return value.GetType() == typeOfT - // run predicate on the 'public key' part only, ie without prefix - && predicate(((string)x.Key).Substring(plen), (T)value); + + //TODO: waiting on a response for this comment: https://github.com/umbraco/Umbraco-CMS/commit/c2db7b2b9b78847a828512818e79492ecc24ac7c#commitcomment-9492329 + // until then we will check if 'T' is an interface and if so we will use the 'is' clause, + // otherwise we do an exact match. + + return ((typeOfT.IsInterface && value is T) || (value.GetType() == typeOfT)) + // run predicate on the 'public key' part only, ie without prefix + && predicate(((string) x.Key).Substring(plen), (T) value); })) RemoveEntry((string) entry.Key); } diff --git a/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs b/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs index 748912b9f1..dcd5198eec 100644 --- a/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs +++ b/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs @@ -20,9 +20,15 @@ namespace Umbraco.Core.Cache private readonly System.Web.Caching.Cache _cache; + /// + /// Used for debugging + /// + internal Guid InstanceId { get; private set; } + public HttpRuntimeCacheProvider(System.Web.Caching.Cache cache) { _cache = cache; + InstanceId = Guid.NewGuid(); } protected override IEnumerable GetDictionaryEntries() diff --git a/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs b/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs index d4f2c33ed1..19fbb0694b 100644 --- a/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs +++ b/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs @@ -16,12 +16,19 @@ namespace Umbraco.Core.Cache /// internal class ObjectCacheRuntimeCacheProvider : IRuntimeCacheProvider { + private readonly ReaderWriterLockSlim _locker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); internal ObjectCache MemoryCache; + /// + /// Used for debugging + /// + internal Guid InstanceId { get; private set; } + public ObjectCacheRuntimeCacheProvider() { MemoryCache = new MemoryCache("in-memory"); + InstanceId = Guid.NewGuid(); } #region Clear @@ -75,7 +82,16 @@ namespace Umbraco.Core.Cache // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null var value = DictionaryCacheProviderBase.GetSafeLazyValue((Lazy)x.Value, true); - return value == null || value.GetType() == typeOfT; + + //TODO: waiting on a response for this comment: https://github.com/umbraco/Umbraco-CMS/commit/c2db7b2b9b78847a828512818e79492ecc24ac7c#commitcomment-9492329 + // until then we will check if 'T' is an interface and if so we will use the 'is' clause, + // otherwise we do an exact match. + + return value == null || + (typeOfT.IsInterface + ? (value is T) + : value.GetType() == typeOfT); + }) .Select(x => x.Key) .ToArray()) // ToArray required to remove @@ -96,8 +112,13 @@ namespace Umbraco.Core.Cache // get non-created as NonCreatedValue & exceptions as null var value = DictionaryCacheProviderBase.GetSafeLazyValue((Lazy)x.Value, true); if (value == null) return true; - return value.GetType() == typeOfT - && predicate(x.Key, (T) value); + + //TODO: waiting on a response for this comment: https://github.com/umbraco/Umbraco-CMS/commit/c2db7b2b9b78847a828512818e79492ecc24ac7c#commitcomment-9492329 + // until then we will check if 'T' is an interface and if so we will use the 'is' clause, + // otherwise we do an exact match. + + return ((typeOfT.IsInterface && value is T) || (value.GetType() == typeOfT)) + && predicate(x.Key, (T)value); }) .Select(x => x.Key) .ToArray()) // ToArray required to remove