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
|
|
|
|
{
|
|
|
|
|
|
/// <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
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-13 12:11:00 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the special disabled instance.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>When used by repositories, all cache policies apply, but the underlying caches do not cache anything.</para>
|
|
|
|
|
|
/// <para>Used by tests.</para>
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public static CacheHelper Disabled { get; } = new CacheHelper(NullCacheProvider.Instance, NullCacheProvider.Instance, NullCacheProvider.Instance, new IsolatedRuntimeCache(_ => NullCacheProvider.Instance));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the special no-cache instance.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>When used by repositories, all cache policies are bypassed.</para>
|
|
|
|
|
|
/// <para>Used by repositories that do no cache.</para>
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public static CacheHelper NoCache { get; } = new CacheHelper(NullCacheProvider.Instance, NullCacheProvider.Instance, NullCacheProvider.Instance, new IsolatedRuntimeCache(_ => NullCacheProvider.Instance));
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|