Streamlines cache helper ctor's
This commit is contained in:
@@ -38,18 +38,6 @@ namespace Umbraco.Core
|
||||
ApplicationCache = cache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor used to specify if we will enable application cache or not, used for unit tests
|
||||
/// </summary>
|
||||
/// <param name="enableCache"></param>
|
||||
internal ApplicationContext(bool enableCache)
|
||||
{
|
||||
//create a new application cache from the HttpRuntime.Cache
|
||||
ApplicationCache = HttpRuntime.Cache == null
|
||||
? new CacheHelper(new System.Web.Caching.Cache(), enableCache)
|
||||
: new CacheHelper(HttpRuntime.Cache, enableCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Singleton accessor
|
||||
/// </summary>
|
||||
|
||||
@@ -25,31 +25,82 @@ namespace Umbraco.Core
|
||||
private readonly IRuntimeCacheProvider _httpCache;
|
||||
private readonly IRuntimeCacheProvider _nullHttpCache = new NullCacheProvider();
|
||||
|
||||
public CacheHelper(System.Web.Caching.Cache cache)
|
||||
: this(cache, true)
|
||||
{
|
||||
}
|
||||
|
||||
internal CacheHelper(System.Web.Caching.Cache cache, bool enableCache)
|
||||
: this(new HttpRuntimeCacheProvider(cache), enableCache)
|
||||
{
|
||||
}
|
||||
|
||||
internal CacheHelper(IRuntimeCacheProvider httpCacheProvider, bool enableCache)
|
||||
: this(httpCacheProvider, new StaticCacheProvider(), new HttpRequestCacheProvider(HttpContext.Current), enableCache)
|
||||
/// <summary>
|
||||
/// Creates a cache helper with disabled caches
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// Good for unit testing
|
||||
/// </remarks>
|
||||
internal static CacheHelper CreateDisabledCacheHelper()
|
||||
{
|
||||
return new CacheHelper(null, null, null, false);
|
||||
}
|
||||
|
||||
internal CacheHelper(
|
||||
/// <summary>
|
||||
/// Initializes a new instance for use in the web
|
||||
/// </summary>
|
||||
public CacheHelper()
|
||||
: this(
|
||||
new HttpRuntimeCacheProvider(HttpRuntime.Cache),
|
||||
new StaticCacheProvider(),
|
||||
new HttpRequestCacheProvider(() => new HttpContextWrapper(HttpContext.Current)))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance for use in the web
|
||||
/// </summary>
|
||||
/// <param name="cache"></param>
|
||||
public CacheHelper(System.Web.Caching.Cache cache)
|
||||
: this(
|
||||
new HttpRuntimeCacheProvider(cache),
|
||||
new StaticCacheProvider(),
|
||||
new HttpRequestCacheProvider(() => new HttpContextWrapper(HttpContext.Current)))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance based on the provided providers
|
||||
/// </summary>
|
||||
/// <param name="httpCacheProvider"></param>
|
||||
/// <param name="staticCacheProvider"></param>
|
||||
/// <param name="requestCacheProvider"></param>
|
||||
public CacheHelper(
|
||||
IRuntimeCacheProvider httpCacheProvider,
|
||||
ICacheProvider staticCacheProvider,
|
||||
ICacheProvider requestCacheProvider)
|
||||
: this(httpCacheProvider, staticCacheProvider, requestCacheProvider, true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Private ctor used for creating a disabled cache helper
|
||||
/// </summary>
|
||||
/// <param name="httpCacheProvider"></param>
|
||||
/// <param name="staticCacheProvider"></param>
|
||||
/// <param name="requestCacheProvider"></param>
|
||||
/// <param name="enableCache"></param>
|
||||
private CacheHelper(
|
||||
IRuntimeCacheProvider httpCacheProvider,
|
||||
ICacheProvider staticCacheProvider,
|
||||
ICacheProvider requestCacheProvider,
|
||||
bool enableCache)
|
||||
{
|
||||
_httpCache = httpCacheProvider;
|
||||
_staticCache = staticCacheProvider;
|
||||
if (enableCache)
|
||||
{
|
||||
_httpCache = httpCacheProvider;
|
||||
_staticCache = staticCacheProvider;
|
||||
_requestCache = requestCacheProvider;
|
||||
}
|
||||
else
|
||||
{
|
||||
_httpCache = null;
|
||||
_staticCache = null;
|
||||
_requestCache = null;
|
||||
}
|
||||
|
||||
_enableCache = enableCache;
|
||||
_requestCache = requestCacheProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.Mapping;
|
||||
@@ -110,7 +111,13 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
protected virtual void CreateApplicationCache()
|
||||
{
|
||||
ApplicationCache = new CacheHelper(new System.Web.Caching.Cache(), true);
|
||||
var cacheHelper = new CacheHelper(
|
||||
new ObjectCacheRuntimeCacheProvider(),
|
||||
new StaticCacheProvider(),
|
||||
//we have no request based cache when not running in web-based context
|
||||
new NullCacheProvider());
|
||||
|
||||
ApplicationCache = cacheHelper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
@@ -45,6 +46,12 @@ namespace Umbraco.Core.Standalone
|
||||
{
|
||||
if (_serviceContext == null)
|
||||
{
|
||||
var cacheHelper = new CacheHelper(
|
||||
new ObjectCacheRuntimeCacheProvider(),
|
||||
new StaticCacheProvider(),
|
||||
//we have no request based cache when running standalone
|
||||
new NullCacheProvider());
|
||||
|
||||
var dbFactory = new DefaultDatabaseFactory(_connectionString, _providerName);
|
||||
var dbContext = new DatabaseContext(dbFactory);
|
||||
Database.Mapper = new PetaPocoMapper();
|
||||
@@ -52,7 +59,7 @@ namespace Umbraco.Core.Standalone
|
||||
new PetaPocoUnitOfWorkProvider(dbFactory),
|
||||
new FileUnitOfWorkProvider(),
|
||||
new PublishingStrategy(),
|
||||
new CacheHelper(new System.Web.Caching.Cache(), true));
|
||||
cacheHelper);
|
||||
|
||||
//initialize the DatabaseContext
|
||||
dbContext.Initialize(_providerName);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
@@ -34,6 +35,15 @@ namespace Umbraco.Web.Standalone
|
||||
{
|
||||
if (_serviceContext == null)
|
||||
{
|
||||
var cacheHelper = new CacheHelper(
|
||||
//SD: Not sure if this is correct? Should we be using HttpRuntime.Cache here since this is for 'Web' ?
|
||||
// just not quite sure what this standalone stuff is.
|
||||
new ObjectCacheRuntimeCacheProvider(),
|
||||
new StaticCacheProvider(),
|
||||
//SD: Not sure if this is correct? Should we be using request cache here since this is for 'Web' ?
|
||||
// just not quite sure what this standalone stuff is.
|
||||
new NullCacheProvider());
|
||||
|
||||
var dbFactory = new DefaultDatabaseFactory(_connectionString, _providerName);
|
||||
var dbContext = new DatabaseContext(dbFactory);
|
||||
Database.Mapper = new PetaPocoMapper();
|
||||
@@ -41,9 +51,7 @@ namespace Umbraco.Web.Standalone
|
||||
new PetaPocoUnitOfWorkProvider(dbFactory),
|
||||
new FileUnitOfWorkProvider(),
|
||||
new PublishingStrategy(),
|
||||
//SD: Not sure if this is correct? Should we be using HttpRuntime.Cache here since this is for 'Web' ?
|
||||
// just not quite sure what this standalone stuff is :)
|
||||
new CacheHelper(new System.Web.Caching.Cache(), true));
|
||||
cacheHelper);
|
||||
|
||||
//initialize the DatabaseContext
|
||||
dbContext.Initialize(_providerName);
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using StackExchange.Profiling.MVCHelpers;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Dynamics;
|
||||
@@ -150,7 +151,8 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
protected override void CreateApplicationCache()
|
||||
{
|
||||
ApplicationCache = new CacheHelper(HttpRuntime.Cache, true);
|
||||
//create a web-based cache helper
|
||||
ApplicationCache = new CacheHelper();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user