using System; using System.Web; namespace Umbraco.Core.Cache { /// /// Represents the application-wide caches. /// public class CacheHelper { /// /// Initializes a new instance for use in the web /// public CacheHelper() : this( new HttpRuntimeCacheProvider(HttpRuntime.Cache), new StaticCacheProvider(), new HttpRequestCacheProvider(), new IsolatedRuntimeCache(t => new ObjectCacheRuntimeCacheProvider())) { } /// /// Initializes a new instance for use in the web /// public CacheHelper(System.Web.Caching.Cache cache) : this( new HttpRuntimeCacheProvider(cache), new StaticCacheProvider(), new HttpRequestCacheProvider(), new IsolatedRuntimeCache(t => new ObjectCacheRuntimeCacheProvider())) { } /// /// Initializes a new instance based on the provided providers /// public CacheHelper( IRuntimeCacheProvider httpCacheProvider, ICacheProvider staticCacheProvider, ICacheProvider requestCacheProvider, 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)); } /// /// 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 CacheHelper Disabled { get; } = new CacheHelper(NullCacheProvider.Instance, NullCacheProvider.Instance, NullCacheProvider.Instance, new IsolatedRuntimeCache(_ => NullCacheProvider.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 CacheHelper NoCache { get; } = new CacheHelper(NullCacheProvider.Instance, NullCacheProvider.Instance, NullCacheProvider.Instance, new IsolatedRuntimeCache(_ => NullCacheProvider.Instance)); /// /// Returns the current Request cache /// public ICacheProvider RequestCache { get; internal set; } /// /// Returns the current Runtime cache /// public ICacheProvider StaticCache { get; internal set; } /// /// Returns the current Runtime cache /// public IRuntimeCacheProvider RuntimeCache { get; internal set; } /// /// Returns the current Isolated Runtime cache manager /// public IsolatedRuntimeCache IsolatedRuntimeCache { get; internal set; } } }