using System; using System.Web; namespace Umbraco.Core.Cache { /// /// Represents the application caches. /// public class AppCaches { /// /// Initializes a new instance of the for use in a web application. /// public AppCaches() : this(HttpRuntime.Cache) { } /// /// Initializes a new instance of the for use in a web application. /// public AppCaches(System.Web.Caching.Cache cache) : this( new WebCachingAppCache(cache), new HttpRequestAppCache(), new IsolatedCaches(t => new ObjectCacheAppCache())) { } /// /// Initializes a new instance of the with cache providers. /// public AppCaches( IAppPolicyCache runtimeCache, IAppCache requestCache, IsolatedCaches isolatedCaches) { RuntimeCache = runtimeCache ?? throw new ArgumentNullException(nameof(runtimeCache)); RequestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache)); IsolatedCaches = isolatedCaches ?? throw new ArgumentNullException(nameof(isolatedCaches)); } /// /// Gets the special disabled instance. /// /// /// When used by repositories, all cache policies apply, but the underlying caches do not cache anything. /// Used by tests. /// public static AppCaches Disabled { get; } = new AppCaches(NoAppCache.Instance, NoAppCache.Instance, new IsolatedCaches(_ => NoAppCache.Instance)); /// /// Gets the special no-cache instance. /// /// /// When used by repositories, all cache policies are bypassed. /// Used by repositories that do no cache. /// public static AppCaches NoCache { get; } = new AppCaches(NoAppCache.Instance, NoAppCache.Instance, new IsolatedCaches(_ => NoAppCache.Instance)); /// /// Gets the per-request cache. /// /// /// The per-request caches works on top of the current HttpContext items. /// Outside a web environment, the behavior of that cache is unspecified. /// public IAppCache RequestCache { get; } /// /// Gets the runtime cache. /// /// /// The runtime cache is the main application cache. /// public IAppPolicyCache RuntimeCache { get; } /// /// Gets the isolated caches. /// /// /// 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. /// public IsolatedCaches IsolatedCaches { get; } } }