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>
|
2019-01-17 11:01:23 +01:00
|
|
|
|
/// Represents the application caches.
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// </summary>
|
2019-01-17 08:34:29 +01:00
|
|
|
|
public class AppCaches
|
2017-07-20 11:21:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2019-01-17 11:01:23 +01:00
|
|
|
|
/// Initializes a new instance of the <see cref="AppCaches"/> for use in a web application.
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// </summary>
|
2019-01-17 08:34:29 +01:00
|
|
|
|
public AppCaches()
|
2019-01-17 11:01:23 +01:00
|
|
|
|
: this(HttpRuntime.Cache)
|
|
|
|
|
|
{ }
|
2017-07-20 11:21:28 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-01-17 11:01:23 +01:00
|
|
|
|
/// Initializes a new instance of the <see cref="AppCaches"/> for use in a web application.
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// </summary>
|
2019-01-17 08:34:29 +01:00
|
|
|
|
public AppCaches(System.Web.Caching.Cache cache)
|
2017-07-20 11:21:28 +02:00
|
|
|
|
: this(
|
2019-01-17 11:01:23 +01:00
|
|
|
|
new WebCachingAppCache(cache),
|
|
|
|
|
|
new HttpRequestAppCache(),
|
|
|
|
|
|
new IsolatedCaches(t => new ObjectCacheAppCache()))
|
|
|
|
|
|
{ }
|
2016-05-18 23:34:56 +02:00
|
|
|
|
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// <summary>
|
2019-01-17 11:01:23 +01:00
|
|
|
|
/// Initializes a new instance of the <see cref="AppCaches"/> with cache providers.
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// </summary>
|
2019-01-17 08:34:29 +01:00
|
|
|
|
public AppCaches(
|
2019-01-18 07:56:38 +01:00
|
|
|
|
IAppPolicyCache runtimeCache,
|
2019-01-17 11:01:23 +01:00
|
|
|
|
IAppCache requestCache,
|
|
|
|
|
|
IsolatedCaches isolatedCaches)
|
2016-05-18 23:34:56 +02:00
|
|
|
|
{
|
2019-01-17 11:01:23 +01:00
|
|
|
|
RuntimeCache = runtimeCache ?? throw new ArgumentNullException(nameof(runtimeCache));
|
|
|
|
|
|
RequestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache));
|
|
|
|
|
|
IsolatedCaches = isolatedCaches ?? throw new ArgumentNullException(nameof(isolatedCaches));
|
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>
|
2019-01-18 15:49:54 +01:00
|
|
|
|
public static AppCaches Disabled { get; } = new AppCaches(NoAppCache.Instance, NoAppCache.Instance, new IsolatedCaches(_ => NoAppCache.Instance));
|
2018-07-13 12:11:00 +02:00
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2019-01-18 15:49:54 +01:00
|
|
|
|
public static AppCaches NoCache { get; } = new AppCaches(NoAppCache.Instance, NoAppCache.Instance, new IsolatedCaches(_ => NoAppCache.Instance));
|
2018-07-13 12:11:00 +02:00
|
|
|
|
|
2016-05-18 23:34:56 +02:00
|
|
|
|
/// <summary>
|
2019-01-17 11:01:23 +01:00
|
|
|
|
/// Gets the per-request cache.
|
2016-05-18 23:34:56 +02:00
|
|
|
|
/// </summary>
|
2019-01-17 11:01:23 +01:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>The per-request caches works on top of the current HttpContext items.</para>
|
2019-01-21 15:39:19 +01:00
|
|
|
|
/// <para>Outside a web environment, the behavior of that cache is unspecified.</para>
|
2019-01-17 11:01:23 +01:00
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public IAppCache RequestCache { get; }
|
2017-07-20 11:21:28 +02:00
|
|
|
|
|
2016-05-18 23:34:56 +02:00
|
|
|
|
/// <summary>
|
2019-01-17 11:01:23 +01:00
|
|
|
|
/// Gets the runtime cache.
|
2016-05-18 23:34:56 +02:00
|
|
|
|
/// </summary>
|
2019-01-17 11:01:23 +01:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>The runtime cache is the main application cache.</para>
|
|
|
|
|
|
/// </remarks>
|
2019-01-18 07:56:38 +01:00
|
|
|
|
public IAppPolicyCache RuntimeCache { get; }
|
2016-05-18 23:34:56 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-01-17 11:01:23 +01:00
|
|
|
|
/// Gets the isolated caches.
|
2016-05-18 23:34:56 +02:00
|
|
|
|
/// </summary>
|
2019-01-17 11:01:23 +01:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>Isolated caches are used by e.g. repositories, to ensure that each cached entity
|
|
|
|
|
|
/// type has its own cache, so that lookups are fast and the repository does not need to
|
|
|
|
|
|
/// search through all keys on a global scale.</para>
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public IsolatedCaches IsolatedCaches { get; }
|
2016-05-18 23:34:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|