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