Ejemplo n.º 1
0
        /// <summary>
        /// Fluent API to create an instance of <see cref="AsyncCachePolicyBuilder{TResult}"/>.
        /// </summary>
        /// <param name="isPolicyEnabled">An overall enablement feature flag for enabling/disabling <see cref="AsyncCachePolicy{TResult}"/>.</param>
        /// <param name="agingStrategy">Cache aging strategy which controls when cache will become stale and expired.</param>
        /// <param name="cacheProvider">Provides the contract to access cache layer</param>
        /// <param name="loggingProvider">Provides the contract to logging <see cref="AsyncCachePolicy{TResult}"/> operations</param>
        /// <returns>A builder to create <see cref="AsyncCachePolicy{TResult}"/></returns>
        public static IFallbackConditionStep <TResult> CreateBuilder(
            bool isPolicyEnabled,
            IAgingStrategy <TResult> agingStrategy,
            ICacheProvider cacheProvider,
            ILoggingProvider <TResult> loggingProvider)
        {
            agingStrategy.ThrowIfNull(nameof(agingStrategy));
            cacheProvider.ThrowIfNull(nameof(cacheProvider));
            loggingProvider.ThrowIfNull(nameof(loggingProvider));

            return(new AsyncCachePolicyBuilder <TResult>(
                       isPolicyEnabled,
                       agingStrategy,
                       cacheProvider,
                       loggingProvider));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AsyncCachePolicy{TResult}"/> class.
        /// </summary>
        /// <param name="isPolicyEnabled">An overall enablement feature flag for enabling/disabling <see cref="AsyncCachePolicy{TResult}"/>.</param>
        /// <param name="policyBuilder">Builder class that holds the list of current execution predicates filtering TResult result values</param>
        /// <param name="agingStrategy">Cache aging strategy which controls when cache will become stale and expired.</param>
        /// <param name="cacheProvider">Provides the contract to access cache layer</param>
        /// <param name="loggingProvider">Provides the contract to logging <see cref="AsyncCachePolicy{TResult}"/> operations</param>
        internal AsyncCachePolicy(
            bool isPolicyEnabled,
            PolicyBuilder <TResult> policyBuilder,
            IAgingStrategy <TResult> agingStrategy,
            ICacheProvider cacheProvider,
            ILoggingProvider <TResult> loggingProvider)
            : base(policyBuilder)
        {
            agingStrategy.ThrowIfNull(nameof(agingStrategy));
            cacheProvider.ThrowIfNull(nameof(cacheProvider));
            loggingProvider.ThrowIfNull(nameof(loggingProvider));

            this.isPolicyEnabled = isPolicyEnabled;
            this.agingStrategy   = agingStrategy;
            this.cacheProvider   = cacheProvider;
            this.loggingProvider = loggingProvider;
        }