2016-05-18 23:34:56 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Cache
|
|
|
|
|
|
{
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// <summary>
|
2018-07-06 18:52:23 +02:00
|
|
|
|
/// Represents the application-wide caches.
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// </summary>
|
2016-05-18 23:34:56 +02:00
|
|
|
|
public class CacheHelper
|
2017-07-20 11:21:28 +02:00
|
|
|
|
{
|
2017-12-15 16:29:14 +01:00
|
|
|
|
public static CacheHelper NoCache { get; } = new CacheHelper(NullCacheProvider.Instance, NullCacheProvider.Instance, NullCacheProvider.Instance, new IsolatedRuntimeCache(_ => NullCacheProvider.Instance));
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// <summary>
|
2016-05-18 23:34:56 +02:00
|
|
|
|
/// Creates a cache helper with disabled caches
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// Good for unit testing
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public static CacheHelper CreateDisabledCacheHelper()
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
// do *not* return NoCache
|
|
|
|
|
|
// NoCache is a special instance that is detected by RepositoryBase and disables all cache policies
|
|
|
|
|
|
// CreateDisabledCacheHelper is used in tests to use no cache, *but* keep all cache policies
|
2018-07-06 18:52:23 +02:00
|
|
|
|
return new DisabledCacheHelper();
|
2016-05-18 23:34:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance for use in the web
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public CacheHelper()
|
|
|
|
|
|
: this(
|
|
|
|
|
|
new HttpRuntimeCacheProvider(HttpRuntime.Cache),
|
|
|
|
|
|
new StaticCacheProvider(),
|
2016-05-18 23:34:56 +02:00
|
|
|
|
new HttpRequestCacheProvider(),
|
|
|
|
|
|
new IsolatedRuntimeCache(t => new ObjectCacheRuntimeCacheProvider()))
|
2017-07-20 11:21:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance for use in the web
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public CacheHelper(System.Web.Caching.Cache cache)
|
|
|
|
|
|
: this(
|
|
|
|
|
|
new HttpRuntimeCacheProvider(cache),
|
|
|
|
|
|
new StaticCacheProvider(),
|
2016-05-18 23:34:56 +02:00
|
|
|
|
new HttpRequestCacheProvider(),
|
|
|
|
|
|
new IsolatedRuntimeCache(t => new ObjectCacheRuntimeCacheProvider()))
|
2017-07-20 11:21:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
}
|
2016-05-18 23:34:56 +02:00
|
|
|
|
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance based on the provided providers
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public CacheHelper(
|
2016-05-18 23:34:56 +02:00
|
|
|
|
IRuntimeCacheProvider httpCacheProvider,
|
|
|
|
|
|
ICacheProvider staticCacheProvider,
|
|
|
|
|
|
ICacheProvider requestCacheProvider,
|
2017-07-20 11:21:28 +02:00
|
|
|
|
IsolatedRuntimeCache isolatedCacheManager)
|
2016-05-18 23:34:56 +02:00
|
|
|
|
{
|
2018-07-06 18:52:23 +02:00
|
|
|
|
RuntimeCache = httpCacheProvider ?? throw new ArgumentNullException(nameof(httpCacheProvider));
|
|
|
|
|
|
StaticCache = staticCacheProvider ?? throw new ArgumentNullException(nameof(staticCacheProvider));
|
|
|
|
|
|
RequestCache = requestCacheProvider ?? throw new ArgumentNullException(nameof(requestCacheProvider));
|
|
|
|
|
|
IsolatedRuntimeCache = isolatedCacheManager ?? throw new ArgumentNullException(nameof(isolatedCacheManager));
|
2016-05-18 23:34:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns the current Request cache
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ICacheProvider RequestCache { get; internal set; }
|
2017-07-20 11:21:28 +02:00
|
|
|
|
|
2016-05-18 23:34:56 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns the current Runtime cache
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ICacheProvider StaticCache { get; internal set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns the current Runtime cache
|
|
|
|
|
|
/// </summary>
|
2017-07-20 11:21:28 +02:00
|
|
|
|
public IRuntimeCacheProvider RuntimeCache { get; internal set; }
|
2016-05-18 23:34:56 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns the current Isolated Runtime cache manager
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public IsolatedRuntimeCache IsolatedRuntimeCache { get; internal set; }
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|