More renaming of caches

This commit is contained in:
Stephan
2019-01-18 08:14:08 +01:00
parent 5aba1a6bd2
commit f952fe7aeb
27 changed files with 178 additions and 193 deletions

View File

@@ -8,7 +8,7 @@ namespace Umbraco.Core.Cache
/// <summary>
/// Extensions for strongly typed access
/// </summary>
public static class CacheProviderExtensions
public static class AppCacheExtensions
{
public static T GetCacheItem<T>(this IAppPolicyCache provider,
string cacheKey,

View File

@@ -105,7 +105,7 @@ 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)
{
// see notes in HttpRuntimeCacheProvider
// see notes in HttpRuntimeAppCache
Lazy<object> result;

View File

@@ -9,7 +9,6 @@ namespace Umbraco.Core.Cache
{
/// <summary>
/// Implements <see cref="IAppPolicyCache"/> on top of a <see cref="System.Web.Caching.Cache"/>.
/// A CacheProvider that wraps the logic of the HttpRuntime.Cache
/// </summary>
/// <remarks>The underlying cache is expected to be HttpRuntime.Cache.</remarks>
internal class WebCachingAppCache : FastDictionaryAppCacheBase, IAppPolicyCache

View File

@@ -180,7 +180,7 @@ namespace Umbraco.Core.Composing
public static ICultureDictionaryFactory CultureDictionaryFactory
=> Factory.GetInstance<ICultureDictionaryFactory>();
public static AppCaches ApplicationCache
public static AppCaches AppCaches
=> Factory.GetInstance<AppCaches>();
public static ServiceContext Services

View File

@@ -124,7 +124,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
var result = Get(qry);
return result.FirstOrDefault();
},
//cache for 5 mins since that is the default in the RuntimeCacheProvider
//cache for 5 mins since that is the default in the Runtime app cache
TimeSpan.FromMinutes(5),
//sliding is true
true);

View File

@@ -114,7 +114,7 @@
<Compile Include="BindingRedirects.cs" />
<Compile Include="Cache\AppCaches.cs" />
<Compile Include="Cache\CacheKeys.cs" />
<Compile Include="Cache\CacheProviderExtensions.cs" />
<Compile Include="Cache\AppCacheExtensions.cs" />
<Compile Include="Cache\CacheRefresherBase.cs" />
<Compile Include="Cache\CacheRefresherCollection.cs" />
<Compile Include="Cache\CacheRefresherCollectionBuilder.cs" />

View File

@@ -7,9 +7,9 @@ using umbraco;
namespace Umbraco.Tests.Cache
{
public abstract class CacheProviderTests
public abstract class AppCacheTests
{
internal abstract IAppCache Provider { get; }
internal abstract IAppCache AppCache { get; }
protected abstract int GetTotalItemCount { get; }
[SetUp]
@@ -21,22 +21,22 @@ namespace Umbraco.Tests.Cache
[TearDown]
public virtual void TearDown()
{
Provider.Clear();
AppCache.Clear();
}
[Test]
public void Throws_On_Reentry()
{
// don't run for StaticCacheProvider - not making sense
if (GetType() == typeof (StaticCacheProviderTests))
if (GetType() == typeof (StaticAppCacheTests))
Assert.Ignore("Do not run for StaticCacheProvider.");
Exception exception = null;
var result = Provider.Get("blah", () =>
var result = AppCache.Get("blah", () =>
{
try
{
var result2 = Provider.Get("blah");
var result2 = AppCache.Get("blah");
}
catch (Exception e)
{
@@ -56,7 +56,7 @@ namespace Umbraco.Tests.Cache
object result;
try
{
result = Provider.Get("Blah", () =>
result = AppCache.Get("Blah", () =>
{
counter++;
throw new Exception("Do not cache this");
@@ -66,7 +66,7 @@ namespace Umbraco.Tests.Cache
try
{
result = Provider.Get("Blah", () =>
result = AppCache.Get("Blah", () =>
{
counter++;
throw new Exception("Do not cache this");
@@ -85,13 +85,13 @@ namespace Umbraco.Tests.Cache
object result;
result = Provider.Get("Blah", () =>
result = AppCache.Get("Blah", () =>
{
counter++;
return "";
});
result = Provider.Get("Blah", () =>
result = AppCache.Get("Blah", () =>
{
counter++;
return "";
@@ -108,14 +108,14 @@ namespace Umbraco.Tests.Cache
var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2");
var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3");
var cacheContent4 = new LiteralControl();
Provider.Get("Test1", () => cacheContent1);
Provider.Get("Tester2", () => cacheContent2);
Provider.Get("Tes3", () => cacheContent3);
Provider.Get("different4", () => cacheContent4);
AppCache.Get("Test1", () => cacheContent1);
AppCache.Get("Tester2", () => cacheContent2);
AppCache.Get("Tes3", () => cacheContent3);
AppCache.Get("different4", () => cacheContent4);
Assert.AreEqual(4, GetTotalItemCount);
var result = Provider.SearchByKey("Tes");
var result = AppCache.SearchByKey("Tes");
Assert.AreEqual(3, result.Count());
}
@@ -127,14 +127,14 @@ namespace Umbraco.Tests.Cache
var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2");
var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3");
var cacheContent4 = new LiteralControl();
Provider.Get("TTes1t", () => cacheContent1);
Provider.Get("Tester2", () => cacheContent2);
Provider.Get("Tes3", () => cacheContent3);
Provider.Get("different4", () => cacheContent4);
AppCache.Get("TTes1t", () => cacheContent1);
AppCache.Get("Tester2", () => cacheContent2);
AppCache.Get("Tes3", () => cacheContent3);
AppCache.Get("different4", () => cacheContent4);
Assert.AreEqual(4, GetTotalItemCount);
Provider.ClearByRegex("^\\w+es\\d.*");
AppCache.ClearByRegex("^\\w+es\\d.*");
Assert.AreEqual(2, GetTotalItemCount);
}
@@ -146,14 +146,14 @@ namespace Umbraco.Tests.Cache
var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2");
var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3");
var cacheContent4 = new LiteralControl();
Provider.Get("Test1", () => cacheContent1);
Provider.Get("Tester2", () => cacheContent2);
Provider.Get("Tes3", () => cacheContent3);
Provider.Get("different4", () => cacheContent4);
AppCache.Get("Test1", () => cacheContent1);
AppCache.Get("Tester2", () => cacheContent2);
AppCache.Get("Tes3", () => cacheContent3);
AppCache.Get("different4", () => cacheContent4);
Assert.AreEqual(4, GetTotalItemCount);
Provider.ClearByKey("Test");
AppCache.ClearByKey("Test");
Assert.AreEqual(2, GetTotalItemCount);
}
@@ -165,15 +165,15 @@ namespace Umbraco.Tests.Cache
var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2");
var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3");
var cacheContent4 = new LiteralControl();
Provider.Get("Test1", () => cacheContent1);
Provider.Get("Test2", () => cacheContent2);
Provider.Get("Test3", () => cacheContent3);
Provider.Get("Test4", () => cacheContent4);
AppCache.Get("Test1", () => cacheContent1);
AppCache.Get("Test2", () => cacheContent2);
AppCache.Get("Test3", () => cacheContent3);
AppCache.Get("Test4", () => cacheContent4);
Assert.AreEqual(4, GetTotalItemCount);
Provider.Clear("Test1");
Provider.Clear("Test2");
AppCache.Clear("Test1");
AppCache.Clear("Test2");
Assert.AreEqual(2, GetTotalItemCount);
}
@@ -185,14 +185,14 @@ namespace Umbraco.Tests.Cache
var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2");
var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3");
var cacheContent4 = new LiteralControl();
Provider.Get("Test1", () => cacheContent1);
Provider.Get("Test2", () => cacheContent2);
Provider.Get("Test3", () => cacheContent3);
Provider.Get("Test4", () => cacheContent4);
AppCache.Get("Test1", () => cacheContent1);
AppCache.Get("Test2", () => cacheContent2);
AppCache.Get("Test3", () => cacheContent3);
AppCache.Get("Test4", () => cacheContent4);
Assert.AreEqual(4, GetTotalItemCount);
Provider.Clear();
AppCache.Clear();
Assert.AreEqual(0, GetTotalItemCount);
}
@@ -201,7 +201,7 @@ namespace Umbraco.Tests.Cache
public void Can_Add_When_Not_Available()
{
var cacheContent1 = new MacroCacheContent(new LiteralControl(), "Test1");
Provider.Get("Test1", () => cacheContent1);
AppCache.Get("Test1", () => cacheContent1);
Assert.AreEqual(1, GetTotalItemCount);
}
@@ -209,8 +209,8 @@ namespace Umbraco.Tests.Cache
public void Can_Get_When_Available()
{
var cacheContent1 = new MacroCacheContent(new LiteralControl(), "Test1");
var result = Provider.Get("Test1", () => cacheContent1);
var result2 = Provider.Get("Test1", () => cacheContent1);
var result = AppCache.Get("Test1", () => cacheContent1);
var result2 = AppCache.Get("Test1", () => cacheContent1);
Assert.AreEqual(1, GetTotalItemCount);
Assert.AreEqual(result, result2);
}
@@ -222,15 +222,15 @@ namespace Umbraco.Tests.Cache
var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2");
var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3");
var cacheContent4 = new LiteralControl();
Provider.Get("Test1", () => cacheContent1);
Provider.Get("Test2", () => cacheContent2);
Provider.Get("Test3", () => cacheContent3);
Provider.Get("Test4", () => cacheContent4);
AppCache.Get("Test1", () => cacheContent1);
AppCache.Get("Test2", () => cacheContent2);
AppCache.Get("Test3", () => cacheContent3);
AppCache.Get("Test4", () => cacheContent4);
Assert.AreEqual(4, GetTotalItemCount);
//Provider.ClearCacheObjectTypes("umbraco.MacroCacheContent");
Provider.ClearOfType(typeof(MacroCacheContent).ToString());
AppCache.ClearOfType(typeof(MacroCacheContent).ToString());
Assert.AreEqual(1, GetTotalItemCount);
}
@@ -242,14 +242,14 @@ namespace Umbraco.Tests.Cache
var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2");
var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3");
var cacheContent4 = new LiteralControl();
Provider.Get("Test1", () => cacheContent1);
Provider.Get("Test2", () => cacheContent2);
Provider.Get("Test3", () => cacheContent3);
Provider.Get("Test4", () => cacheContent4);
AppCache.Get("Test1", () => cacheContent1);
AppCache.Get("Test2", () => cacheContent2);
AppCache.Get("Test3", () => cacheContent3);
AppCache.Get("Test4", () => cacheContent4);
Assert.AreEqual(4, GetTotalItemCount);
Provider.ClearOfType<MacroCacheContent>();
AppCache.ClearOfType<MacroCacheContent>();
Assert.AreEqual(1, GetTotalItemCount);
}

View File

@@ -8,13 +8,12 @@ using Umbraco.Core.Cache;
using Umbraco.Core.Collections;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Tests.Collections;
namespace Umbraco.Tests.Cache
{
[TestFixture]
public class DeepCloneRuntimeCacheProviderTests : RuntimeCacheProviderTests
public class DeepCloneAppCacheTests : RuntimeAppCacheTests
{
private DeepCloneAppCache _provider;
@@ -29,12 +28,12 @@ namespace Umbraco.Tests.Cache
_provider = new DeepCloneAppCache(new WebCachingAppCache(HttpRuntime.Cache));
}
internal override IAppCache Provider
internal override IAppCache AppCache
{
get { return _provider; }
}
internal override IAppPolicyCache RuntimeProvider
internal override IAppPolicyCache AppPolicyCache
{
get { return _provider; }
}

View File

@@ -5,7 +5,7 @@ using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests.Cache
{
[TestFixture]
public class HttpRequestCacheProviderTests : CacheProviderTests
public class HttpRequestAppCacheTests : AppCacheTests
{
private HttpRequestAppCache _provider;
private FakeHttpContextFactory _ctx;
@@ -17,7 +17,7 @@ namespace Umbraco.Tests.Cache
_provider = new HttpRequestAppCache(_ctx.HttpContext);
}
internal override IAppCache Provider
internal override IAppCache AppCache
{
get { return _provider; }
}
@@ -29,7 +29,7 @@ namespace Umbraco.Tests.Cache
}
[TestFixture]
public class StaticCacheProviderTests : CacheProviderTests
public class StaticAppCacheTests : AppCacheTests
{
private DictionaryCacheProvider _provider;
@@ -39,7 +39,7 @@ namespace Umbraco.Tests.Cache
_provider = new DictionaryCacheProvider();
}
internal override IAppCache Provider
internal override IAppCache AppCache
{
get { return _provider; }
}

View File

@@ -1,59 +0,0 @@
using System;
using System.Diagnostics;
using System.Web;
using NUnit.Framework;
using Umbraco.Core.Cache;
namespace Umbraco.Tests.Cache
{
[TestFixture]
public class HttpRuntimeCacheProviderTests : RuntimeCacheProviderTests
{
private WebCachingAppCache _provider;
protected override int GetTotalItemCount
{
get { return HttpRuntime.Cache.Count; }
}
public override void Setup()
{
base.Setup();
_provider = new WebCachingAppCache(HttpRuntime.Cache);
}
internal override IAppCache Provider
{
get { return _provider; }
}
internal override IAppPolicyCache RuntimeProvider
{
get { return _provider; }
}
[Test]
public void DoesNotCacheExceptions()
{
string value;
Assert.Throws<Exception>(() => { value = (string)_provider.Get("key", () => GetValue(1)); });
Assert.Throws<Exception>(() => { value = (string)_provider.Get("key", () => GetValue(2)); });
// does not throw
value = (string)_provider.Get("key", () => GetValue(3));
Assert.AreEqual("succ3", value);
// cache
value = (string)_provider.Get("key", () => GetValue(4));
Assert.AreEqual("succ3", value);
}
private static string GetValue(int i)
{
Debug.Print("get" + i);
if (i < 3)
throw new Exception("fail");
return "succ" + i;
}
}
}

View File

@@ -8,7 +8,7 @@ using Umbraco.Core.Cache;
namespace Umbraco.Tests.Cache
{
[TestFixture]
public class ObjectCacheProviderTests : RuntimeCacheProviderTests
public class ObjectAppCacheTests : RuntimeAppCacheTests
{
private ObjectCacheAppCache _provider;
@@ -23,12 +23,12 @@ namespace Umbraco.Tests.Cache
_provider = new ObjectCacheAppCache();
}
internal override IAppCache Provider
internal override IAppCache AppCache
{
get { return _provider; }
}
internal override IAppPolicyCache RuntimeProvider
internal override IAppPolicyCache AppPolicyCache
{
get { return _provider; }
}

View File

@@ -63,12 +63,12 @@ namespace Umbraco.Tests.Cache.PublishedCache
_xml = new XmlDocument();
_xml.LoadXml(GetXml());
var xmlStore = new XmlStore(() => _xml, null, null, null);
var cacheProvider = new DictionaryCacheProvider();
var appCache = new DictionaryCacheProvider();
var domainCache = new DomainCache(ServiceContext.DomainService, DefaultCultureAccessor);
var publishedShapshot = new Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedSnapshot(
new PublishedContentCache(xmlStore, domainCache, cacheProvider, globalSettings, new SiteDomainHelper(), ContentTypesCache, null, null),
new PublishedMediaCache(xmlStore, ServiceContext.MediaService, ServiceContext.UserService, cacheProvider, ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>()),
new PublishedMemberCache(null, cacheProvider, Current.Services.MemberService, ContentTypesCache),
new PublishedContentCache(xmlStore, domainCache, appCache, globalSettings, new SiteDomainHelper(), ContentTypesCache, null, null),
new PublishedMediaCache(xmlStore, ServiceContext.MediaService, ServiceContext.UserService, appCache, ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>()),
new PublishedMemberCache(null, appCache, Current.Services.MemberService, ContentTypesCache),
domainCache);
var publishedSnapshotService = new Mock<IPublishedSnapshotService>();
publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(publishedShapshot);

View File

@@ -5,25 +5,23 @@ using Umbraco.Core.Cache;
namespace Umbraco.Tests.Cache
{
public abstract class RuntimeCacheProviderTests : CacheProviderTests
public abstract class RuntimeAppCacheTests : AppCacheTests
{
internal abstract IAppPolicyCache RuntimeProvider { get; }
internal abstract IAppPolicyCache AppPolicyCache { get; }
[Test]
[Explicit("Testing for timeouts cannot work on VSTS.")]
public void Can_Add_And_Expire_Struct_Strongly_Typed_With_Null()
{
var now = DateTime.Now;
RuntimeProvider.Insert("DateTimeTest", () => now, new TimeSpan(0, 0, 0, 0, 200));
Assert.AreEqual(now, Provider.GetCacheItem<DateTime>("DateTimeTest"));
Assert.AreEqual(now, Provider.GetCacheItem<DateTime?>("DateTimeTest"));
AppPolicyCache.Insert("DateTimeTest", () => now, new TimeSpan(0, 0, 0, 0, 200));
Assert.AreEqual(now, AppCache.GetCacheItem<DateTime>("DateTimeTest"));
Assert.AreEqual(now, AppCache.GetCacheItem<DateTime?>("DateTimeTest"));
Thread.Sleep(300); //sleep longer than the cache expiration
Assert.AreEqual(default(DateTime), Provider.GetCacheItem<DateTime>("DateTimeTest"));
Assert.AreEqual(null, Provider.GetCacheItem<DateTime?>("DateTimeTest"));
Assert.AreEqual(default(DateTime), AppCache.GetCacheItem<DateTime>("DateTimeTest"));
Assert.AreEqual(null, AppCache.GetCacheItem<DateTime?>("DateTimeTest"));
}
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Diagnostics;
using System.Web;
using NUnit.Framework;
using Umbraco.Core.Cache;
namespace Umbraco.Tests.Cache
{
[TestFixture]
public class WebCachingAppCacheTests : RuntimeAppCacheTests
{
private WebCachingAppCache _appCache;
protected override int GetTotalItemCount => HttpRuntime.Cache.Count;
public override void Setup()
{
base.Setup();
_appCache = new WebCachingAppCache(HttpRuntime.Cache);
}
internal override IAppCache AppCache => _appCache;
internal override IAppPolicyCache AppPolicyCache => _appCache;
[Test]
public void DoesNotCacheExceptions()
{
string value;
Assert.Throws<Exception>(() => { value = (string)_appCache.Get("key", () => GetValue(1)); });
Assert.Throws<Exception>(() => { value = (string)_appCache.Get("key", () => GetValue(2)); });
// does not throw
value = (string)_appCache.Get("key", () => GetValue(3));
Assert.AreEqual("succ3", value);
// cache
value = (string)_appCache.Get("key", () => GetValue(4));
Assert.AreEqual("succ3", value);
}
private static string GetValue(int i)
{
Debug.Print("get" + i);
if (i < 3)
throw new Exception("fail");
return "succ" + i;
}
}
}

View File

@@ -60,7 +60,7 @@ namespace Umbraco.Tests.Scoping
{
var scopeProvider = ScopeProvider;
var service = Current.Services.UserService;
var globalCache = Current.ApplicationCache.IsolatedCaches.GetOrCreate(typeof(IUser));
var globalCache = Current.AppCaches.IsolatedCaches.GetOrCreate(typeof(IUser));
var user = (IUser)new User("name", "email", "username", "rawPassword");
service.Save(user);
@@ -137,7 +137,7 @@ namespace Umbraco.Tests.Scoping
{
var scopeProvider = ScopeProvider;
var service = Current.Services.LocalizationService;
var globalCache = Current.ApplicationCache.IsolatedCaches.GetOrCreate(typeof (ILanguage));
var globalCache = Current.AppCaches.IsolatedCaches.GetOrCreate(typeof (ILanguage));
var lang = (ILanguage) new Language("fr-FR");
service.Save(lang);
@@ -229,7 +229,7 @@ namespace Umbraco.Tests.Scoping
{
var scopeProvider = ScopeProvider;
var service = Current.Services.LocalizationService;
var globalCache = Current.ApplicationCache.IsolatedCaches.GetOrCreate(typeof (IDictionaryItem));
var globalCache = Current.AppCaches.IsolatedCaches.GetOrCreate(typeof (IDictionaryItem));
var lang = (ILanguage)new Language("fr-FR");
service.Save(lang);

View File

@@ -225,7 +225,7 @@
<Compile Include="CoreThings\AttemptTests.cs" />
<Compile Include="Migrations\Stubs\DropForeignKeyMigrationStub.cs" />
<Compile Include="Models\Mapping\ContentTypeModelMappingTests.cs" />
<Compile Include="Cache\DeepCloneRuntimeCacheProviderTests.cs" />
<Compile Include="Cache\DeepCloneAppCacheTests.cs" />
<Compile Include="Cache\DefaultCachePolicyTests.cs" />
<Compile Include="Cache\FullDataSetCachePolicyTests.cs" />
<Compile Include="Cache\SingleItemsOnlyCachePolicyTests.cs" />
@@ -286,11 +286,11 @@
<Compile Include="Web\Mvc\UmbracoViewPageTests.cs" />
<Compile Include="Runtimes\CoreRuntimeTests.cs" />
<Compile Include="Runtimes\WebRuntimeComponentTests.cs" />
<Compile Include="Cache\ObjectCacheProviderTests.cs" />
<Compile Include="Cache\CacheProviderTests.cs" />
<Compile Include="Cache\HttpRequestCacheProviderTests.cs" />
<Compile Include="Cache\HttpRuntimeCacheProviderTests.cs" />
<Compile Include="Cache\RuntimeCacheProviderTests.cs" />
<Compile Include="Cache\ObjectAppCacheTests.cs" />
<Compile Include="Cache\AppCacheTests.cs" />
<Compile Include="Cache\HttpRequestAppCacheTests.cs" />
<Compile Include="Cache\WebCachingAppCacheTests.cs" />
<Compile Include="Cache\RuntimeAppCacheTests.cs" />
<Compile Include="Configurations\DashboardSettings\DashboardSettingsTests.cs" />
<Compile Include="Configurations\FileSystemProviderTests.cs" />
<Compile Include="Configurations\UmbracoSettings\ContentElementDefaultTests.cs" />

View File

@@ -102,7 +102,7 @@ namespace Umbraco.Web.Cache
if (payloads.Any(x => x.ChangeTypes.HasType(TreeChangeTypes.RefreshAll)) || publishedChanged)
{
// when a public version changes
Current.ApplicationCache.ClearPartialViewCache();
Current.AppCaches.ClearPartialViewCache();
MacroCacheRefresher.ClearMacroContentCache(AppCaches); // just the content
}

View File

@@ -47,7 +47,7 @@ namespace Umbraco.Web.Cache
if (anythingChanged)
{
Current.ApplicationCache.ClearPartialViewCache();
Current.AppCaches.ClearPartialViewCache();
var mediaCache = AppCaches.IsolatedCaches.Get<IMedia>();

View File

@@ -203,7 +203,7 @@ namespace Umbraco.Web.Composing
public static IProfilingLogger ProfilingLogger => CoreCurrent.ProfilingLogger;
public static AppCaches ApplicationCache => CoreCurrent.ApplicationCache;
public static AppCaches AppCaches => CoreCurrent.AppCaches;
public static ServiceContext Services => CoreCurrent.Services;

View File

@@ -21,31 +21,29 @@ namespace Umbraco.Web.Dictionary
public class DefaultCultureDictionary : Core.Dictionary.ICultureDictionary
{
private readonly ILocalizationService _localizationService;
private readonly IAppCache _requestCacheProvider;
private readonly IAppCache _requestCache;
private readonly CultureInfo _specificCulture;
public DefaultCultureDictionary()
: this(Current.Services.LocalizationService, Current.ApplicationCache.RequestCache)
{
: this(Current.Services.LocalizationService, Current.AppCaches.RequestCache)
{ }
}
public DefaultCultureDictionary(ILocalizationService localizationService, IAppCache requestCacheProvider)
public DefaultCultureDictionary(ILocalizationService localizationService, IAppCache requestCache)
{
_localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
_requestCacheProvider = requestCacheProvider ?? throw new ArgumentNullException(nameof(requestCacheProvider));
_requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache));
}
public DefaultCultureDictionary(CultureInfo specificCulture)
: this(Current.Services.LocalizationService, Current.ApplicationCache.RequestCache)
: this(Current.Services.LocalizationService, Current.AppCaches.RequestCache)
{
_specificCulture = specificCulture ?? throw new ArgumentNullException(nameof(specificCulture));
}
public DefaultCultureDictionary(CultureInfo specificCulture, ILocalizationService localizationService, IAppCache requestCacheProvider)
public DefaultCultureDictionary(CultureInfo specificCulture, ILocalizationService localizationService, IAppCache requestCache)
{
_localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
_requestCacheProvider = requestCacheProvider ?? throw new ArgumentNullException(nameof(requestCacheProvider));
_requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache));
_specificCulture = specificCulture ?? throw new ArgumentNullException(nameof(specificCulture));
}
@@ -123,7 +121,7 @@ namespace Umbraco.Web.Dictionary
{
//ensure it's stored/retrieved from request cache
//NOTE: This is no longer necessary since these are cached at the runtime level, but we can leave it here for now.
return _requestCacheProvider.GetCacheItem<ILanguage>(typeof (DefaultCultureDictionary).Name + "Culture" + Culture.Name,
return _requestCache.GetCacheItem<ILanguage>(typeof (DefaultCultureDictionary).Name + "Culture" + Culture.Name,
() => _localizationService.GetLanguageByIsoCode(Culture.Name));
}
}

View File

@@ -157,7 +157,7 @@ namespace Umbraco.Web.Editors
public async Task<HttpResponseMessage> PostSetAvatar()
{
//borrow the logic from the user controller
return await UsersController.PostSetAvatarInternal(Request, Services.UserService, Current.ApplicationCache.StaticCache, Security.GetUserId().ResultOr(0));
return await UsersController.PostSetAvatarInternal(Request, Services.UserService, Current.AppCaches.StaticCache, Security.GetUserId().ResultOr(0));
}
/// <summary>

View File

@@ -105,7 +105,7 @@ namespace Umbraco.Web
var contextualKey = contextualKeyBuilder(model, viewData);
cacheKey.AppendFormat("c{0}-", contextualKey);
}
return Current.ApplicationCache.CachedPartialView(htmlHelper, partialViewName, model, cachedSeconds, cacheKey.ToString(), viewData);
return Current.AppCaches.CachedPartialView(htmlHelper, partialViewName, model, cachedSeconds, cacheKey.ToString(), viewData);
}
public static MvcHtmlString EditorFor<T>(this HtmlHelper htmlHelper, string templateName = "", string htmlFieldName = "", object additionalViewData = null)

View File

@@ -94,7 +94,7 @@ namespace Umbraco.Web.Macros
// only if cache is enabled
if (UmbracoContext.Current.InPreviewMode || model.CacheDuration <= 0) return null;
var cache = Current.ApplicationCache.RuntimeCache;
var cache = Current.AppCaches.RuntimeCache;
var macroContent = cache.GetCacheItem<MacroContent>(CacheKeys.MacroContentCacheKey + model.CacheIdentifier);
if (macroContent == null) return null;
@@ -151,7 +151,7 @@ namespace Umbraco.Web.Macros
// remember when we cache the content
macroContent.Date = DateTime.Now;
var cache = Current.ApplicationCache.RuntimeCache;
var cache = Current.AppCaches.RuntimeCache;
cache.Insert(
CacheKeys.MacroContentCacheKey + model.CacheIdentifier,
() => macroContent,

View File

@@ -35,7 +35,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
Func<int, IPublishedContent> getParent,
Func<int, XPathNavigator, IEnumerable<IPublishedContent>> getChildren,
Func<DictionaryPublishedContent, string, IPublishedProperty> getProperty,
IAppCache cacheProvider,
IAppCache appCache,
PublishedContentTypeCache contentTypeCache,
XPathNavigator nav,
bool fromExamine)
@@ -47,7 +47,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
_getParent = new Lazy<IPublishedContent>(() => getParent(ParentId));
_getChildren = new Lazy<IEnumerable<IPublishedContent>>(() => getChildren(Id, nav));
_getProperty = getProperty;
_cacheProvider = cacheProvider;
_appCache = appCache;
LoadedFromExamine = fromExamine;
@@ -133,7 +133,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
//private readonly Func<DictionaryPublishedContent, IEnumerable<IPublishedContent>> _getChildren;
private readonly Lazy<IEnumerable<IPublishedContent>> _getChildren;
private readonly Func<DictionaryPublishedContent, string, IPublishedProperty> _getProperty;
private readonly IAppCache _cacheProvider;
private readonly IAppCache _appCache;
/// <summary>
/// Returns 'Media' as the item type

View File

@@ -15,7 +15,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
{
internal class PublishedContentCache : PublishedCacheBase, IPublishedContentCache
{
private readonly IAppCache _cacheProvider;
private readonly IAppCache _appCache;
private readonly IGlobalSettings _globalSettings;
private readonly RoutesCache _routesCache;
private readonly IDomainCache _domainCache;
@@ -24,13 +24,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
// initialize a PublishedContentCache instance with
// an XmlStore containing the master xml
// an ICacheProvider that should be at request-level
// an IAppCache that should be at request-level
// a RoutesCache - need to cleanup that one
// a preview token string (or null if not previewing)
public PublishedContentCache(
XmlStore xmlStore, // an XmlStore containing the master xml
IDomainCache domainCache, // an IDomainCache implementation
IAppCache cacheProvider, // an ICacheProvider that should be at request-level
IAppCache appCache, // an IAppCache that should be at request-level
IGlobalSettings globalSettings,
ISiteDomainHelper siteDomainHelper,
PublishedContentTypeCache contentTypeCache, // a PublishedContentType cache
@@ -38,7 +38,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
string previewToken) // a preview token string (or null if not previewing)
: base(previewToken.IsNullOrWhiteSpace() == false)
{
_cacheProvider = cacheProvider;
_appCache = appCache;
_globalSettings = globalSettings;
_routesCache = routesCache; // may be null for unit-testing
_contentTypeCache = contentTypeCache;
@@ -315,13 +315,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
private IPublishedContent ConvertToDocument(XmlNode xmlNode, bool isPreviewing)
{
return xmlNode == null ? null : XmlPublishedContent.Get(xmlNode, isPreviewing, _cacheProvider, _contentTypeCache);
return xmlNode == null ? null : XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache);
}
private IEnumerable<IPublishedContent> ConvertToDocuments(XmlNodeList xmlNodes, bool isPreviewing)
{
return xmlNodes.Cast<XmlNode>()
.Select(xmlNode => XmlPublishedContent.Get(xmlNode, isPreviewing, _cacheProvider, _contentTypeCache));
.Select(xmlNode => XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache));
}
#endregion
@@ -517,8 +517,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
// clear recursive properties cached by XmlPublishedContent.GetProperty
// assume that nothing else is going to cache IPublishedProperty items (else would need to do ByKeySearch)
// NOTE also clears all the media cache properties, which is OK (see media cache)
_cacheProvider.ClearOfType<IPublishedProperty>();
//_cacheProvider.ClearCacheByKeySearch("XmlPublishedCache.PublishedContentCache:RecursiveProperty-");
_appCache.ClearOfType<IPublishedProperty>();
//_appCache.ClearCacheByKeySearch("XmlPublishedCache.PublishedContentCache:RecursiveProperty-");
}
#endregion

View File

@@ -43,15 +43,15 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
private readonly IEntityXmlSerializer _entitySerializer;
// must be specified by the ctor
private readonly IAppCache _cacheProvider;
private readonly IAppCache _appCache;
public PublishedMediaCache(XmlStore xmlStore, IMediaService mediaService, IUserService userService, IAppCache cacheProvider, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer)
public PublishedMediaCache(XmlStore xmlStore, IMediaService mediaService, IUserService userService, IAppCache appCache, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer)
: base(false)
{
_mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService));
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
_cacheProvider = cacheProvider;
_appCache = appCache;
_xmlStore = xmlStore;
_contentTypeCache = contentTypeCache;
_entitySerializer = entitySerializer;
@@ -63,16 +63,16 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
/// <param name="mediaService"></param>
/// <param name="userService"></param>
/// <param name="searchProvider"></param>
/// <param name="cacheProvider"></param>
/// <param name="appCache"></param>
/// <param name="contentTypeCache"></param>
/// <param name="entitySerializer"></param>
internal PublishedMediaCache(IMediaService mediaService, IUserService userService, ISearcher searchProvider, IAppCache cacheProvider, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer)
internal PublishedMediaCache(IMediaService mediaService, IUserService userService, ISearcher searchProvider, IAppCache appCache, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer)
: base(false)
{
_mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService));
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
_searchProvider = searchProvider ?? throw new ArgumentNullException(nameof(searchProvider));
_cacheProvider = cacheProvider;
_appCache = appCache;
_contentTypeCache = contentTypeCache;
_entitySerializer = entitySerializer;
}
@@ -598,8 +598,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
// clear recursive properties cached by XmlPublishedContent.GetProperty
// assume that nothing else is going to cache IPublishedProperty items (else would need to do ByKeySearch)
// NOTE all properties cleared when clearing the content cache (see content cache)
//_cacheProvider.ClearCacheObjectTypes<IPublishedProperty>();
//_cacheProvider.ClearCacheByKeySearch("XmlPublishedCache.PublishedMediaCache:RecursiveProperty-");
//_appCache.ClearCacheObjectTypes<IPublishedProperty>();
//_appCache.ClearCacheByKeySearch("XmlPublishedCache.PublishedMediaCache:RecursiveProperty-");
}
#region Content types
@@ -663,7 +663,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
parentId => parentId < 0 ? null : GetUmbracoMedia(parentId),
GetChildrenMedia,
GetProperty,
_cacheProvider,
_appCache,
_contentTypeCache,
cacheValues.XPath, // though, outside of tests, that should be null
cacheValues.FromExamine
@@ -676,14 +676,14 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
if (_publishedMediaCacheEnabled == false)
return func(id);
var cache = Current.ApplicationCache.RuntimeCache;
var cache = Current.AppCaches.RuntimeCache;
var key = PublishedMediaCacheKey + id;
return (CacheValues)cache.Get(key, () => func(id), _publishedMediaCacheTimespan);
}
internal static void ClearCache(int id)
{
var cache = Current.ApplicationCache.RuntimeCache;
var cache = Current.AppCaches.RuntimeCache;
var sid = id.ToString();
var key = PublishedMediaCacheKey + sid;

View File

@@ -20,18 +20,18 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
[XmlType(Namespace = "http://umbraco.org/webservices/")]
internal class XmlPublishedContent : PublishedContentBase
{
private XmlPublishedContent(XmlNode xmlNode, bool isPreviewing, IAppCache cacheProvider, PublishedContentTypeCache contentTypeCache)
private XmlPublishedContent(XmlNode xmlNode, bool isPreviewing, IAppCache appCache, PublishedContentTypeCache contentTypeCache)
{
_xmlNode = xmlNode;
_isPreviewing = isPreviewing;
_cacheProvider = cacheProvider;
_appCache = appCache;
_contentTypeCache = contentTypeCache;
}
private readonly XmlNode _xmlNode;
private readonly bool _isPreviewing;
private readonly IAppCache _cacheProvider; // at snapshot/request level (see PublishedContentCache)
private readonly IAppCache _appCache; // at snapshot/request level (see PublishedContentCache)
private readonly PublishedContentTypeCache _contentTypeCache;
private readonly object _initializeLock = new object();
@@ -252,7 +252,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
if (parent == null) return;
if (parent.Attributes?.GetNamedItem("isDoc") != null)
_parent = Get(parent, _isPreviewing, _cacheProvider, _contentTypeCache);
_parent = Get(parent, _isPreviewing, _appCache, _contentTypeCache);
_parentInitialized = true;
}
@@ -409,7 +409,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
var iterator = nav.Select(expr);
_children = iterator.Cast<XPathNavigator>()
.Select(n => Get(((IHasXmlNode) n).GetNode(), _isPreviewing, _cacheProvider, _contentTypeCache))
.Select(n => Get(((IHasXmlNode) n).GetNode(), _isPreviewing, _appCache, _contentTypeCache))
.OrderBy(x => x.SortOrder)
.ToList();
@@ -440,7 +440,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
public static void ClearRequest()
{
Current.ApplicationCache.RequestCache.ClearByKey(CacheKeyPrefix);
Current.AppCaches.RequestCache.ClearByKey(CacheKeyPrefix);
}
private const string CacheKeyPrefix = "CONTENTCACHE_XMLPUBLISHEDCONTENT_";