Fixes: U4-6202 Cache not clearing by object type properly

Conflicts:
	src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs
This commit is contained in:
Shannon
2015-07-08 11:07:53 +02:00
parent a1f4d7b16f
commit 3e7c9fc81e
3 changed files with 47 additions and 7 deletions

View File

@@ -16,12 +16,19 @@ namespace Umbraco.Core.Cache
/// </summary>
internal class ObjectCacheRuntimeCacheProvider : IRuntimeCacheProvider
{
private readonly ReaderWriterLockSlim _locker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
internal ObjectCache MemoryCache;
/// <summary>
/// Used for debugging
/// </summary>
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<object>)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<object>)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