Files
Umbraco-CMS/src/Umbraco.Tests/LegacyXmlPublishedCache/UmbracoContextCache.cs

26 lines
931 B
C#
Raw Normal View History

using System.Collections.Concurrent;
2018-06-29 19:52:40 +02:00
using System.Runtime.CompilerServices;
using Umbraco.Web;
2018-06-29 19:52:40 +02:00
namespace Umbraco.Tests.LegacyXmlPublishedCache
2018-06-29 19:52:40 +02:00
{
static class UmbracoContextCache
{
static readonly ConditionalWeakTable<UmbracoContext, ConcurrentDictionary<string, object>> Caches
= new ConditionalWeakTable<UmbracoContext, ConcurrentDictionary<string, object>>();
public static ConcurrentDictionary<string, object> Current
{
get
{
2019-02-14 09:49:45 +01:00
var umbracoContext = Umbraco.Web.Composing.Current.UmbracoContext;
2018-06-29 19:52:40 +02:00
// will get or create a value
// a ConditionalWeakTable is thread-safe
// does not prevent the context from being disposed, and then the dictionary will be disposed too
return umbracoContext == null ? null : Caches.GetOrCreateValue(umbracoContext);
}
}
}
}