Explicit exception on cache reentry

This commit is contained in:
Stephan
2015-05-21 16:01:05 +02:00
parent 72046a6ab9
commit b804ff6107
2 changed files with 33 additions and 2 deletions

View File

@@ -61,8 +61,15 @@ namespace Umbraco.Core.Cache
if (lazy.Value is ExceptionHolder) return null;
// we have a value and execution has not thrown so returning
// here does not throw
return lazy.Value;
// 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

View File

@@ -24,6 +24,30 @@ namespace Umbraco.Tests.Cache
Provider.ClearAllCache();
}
[Test]
public void Throws_On_Reentry()
{
// don't run for StaticCacheProvider - not making sense
if (GetType() == typeof (StaticCacheProviderTests))
Assert.Ignore("Do not run for StaticCacheProvider.");
Exception exception = null;
var result = Provider.GetCacheItem("blah", () =>
{
try
{
var result2 = Provider.GetCacheItem("blah");
}
catch (Exception e)
{
exception = e;
}
return "value";
});
Assert.IsNotNull(exception);
Assert.IsAssignableFrom<InvalidOperationException>(exception);
}
[Test]
public void Does_Not_Cache_Exceptions()
{