Files
Umbraco-CMS/src/Umbraco.Core/Cache/CacheHelper.cs

91 lines
3.5 KiB
C#
Raw Normal View History

using System;
using System.Web;
namespace Umbraco.Core.Cache
{
2017-07-20 11:21:28 +02:00
/// <summary>
/// Represents the application-wide caches.
2017-07-20 11:21:28 +02:00
/// </summary>
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(),
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(),
new HttpRequestCacheProvider(),
new IsolatedRuntimeCache(t => new ObjectCacheRuntimeCacheProvider()))
2017-07-20 11:21:28 +02:00
{
}
2017-07-20 11:21:28 +02:00
/// <summary>
/// Initializes a new instance based on the provided providers
/// </summary>
public CacheHelper(
IRuntimeCacheProvider httpCacheProvider,
ICacheProvider staticCacheProvider,
ICacheProvider requestCacheProvider,
2017-07-20 11:21:28 +02:00
IsolatedRuntimeCache isolatedCacheManager)
{
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));
}
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));
/// <summary>
/// Returns the current Request cache
/// </summary>
public ICacheProvider RequestCache { get; internal set; }
2017-07-20 11:21:28 +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; }
/// <summary>
/// Returns the current Isolated Runtime cache manager
/// </summary>
public IsolatedRuntimeCache IsolatedRuntimeCache { get; internal set; }
}
}