public CustomResponseCachingMiddleware(RequestDelegate next,
                                        IOptions <ResponseCachingOptions> options,
                                        ILoggerFactory loggerFactory,
                                        IResponseCachingPolicyProvider policyProvider,
                                        ICustomResponseCache cache,
                                        IResponseCachingKeyProvider keyProvider)
 {
     responseCachingMiddleware = new ResponseCachingMiddleware(next, options, loggerFactory, policyProvider, cache, keyProvider);
 }
        public DistributedResponseCachingMiddleware(RequestDelegate next,
                                                    IOptions <ResponseCachingOptions> options,
                                                    ILoggerFactory loggerFactory,
                                                    IResponseCachingPolicyProvider policyProvider,
                                                    IDistributedCache cache,
                                                    IResponseCachingKeyProvider keyProvider)
        {
            var distributedResponseCache = new DistributedResponseCache(cache);

            responseCachingMiddleware = new ResponseCachingMiddleware(next, options, loggerFactory, policyProvider, distributedResponseCache, keyProvider);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="T:EasyCaching.ResponseCaching.EasyCachingResponseCachingMiddleware"/> class.
        /// </summary>
        /// <param name="next">Next.</param>
        /// <param name="options">Options.</param>
        /// <param name="cache">Cache.</param>
        /// <param name="loggerFactory">Logger factory.</param>
        /// <param name="policyProvider">Policy provider.</param>
        /// <param name="keyProvider">Key provider.</param>
        public EasyCachingResponseCachingMiddleware(
            RequestDelegate next,
            IOptions <ResponseCachingOptions> options,
            IResponseCache cache,
            ILoggerFactory loggerFactory,
            IResponseCachingPolicyProvider policyProvider,
            IResponseCachingKeyProvider keyProvider)
            : base(next, options, loggerFactory, policyProvider, keyProvider)
        {
            FieldInfo cacheFieldInfo = typeof(ResponseCachingMiddleware).GetField("_cache", BindingFlags.NonPublic | BindingFlags.Instance);

            cacheFieldInfo.SetValue(this, cache);
        }
 public ResponseCachingCustomMiddleware(
     RequestDelegate next,
     IOptions <ResponseCachingOptions> options,
     ILoggerFactory loggerFactory,
     IResponseCachingPolicyProvider policyProvider,
     IResponseCachingKeyProvider keyProvider)
     : base(
         next,
         options,
         loggerFactory,
         policyProvider,
         keyProvider)
 {
     loggerFactory.CreateLogger <ResponseCachingMiddleware>().LogInformation("Response Caching Middleware Initialised");
     Instance = this;
 }
 public ResponseCachingMiddleware(
     RequestDelegate next,
     IOptions <ResponseCachingOptions> options,
     ILoggerFactory loggerFactory,
     IResponseCachingPolicyProvider policyProvider,
     IResponseCachingKeyProvider keyProvider)
     : this(
         next,
         options,
         loggerFactory,
         policyProvider,
         new MemoryResponseCache(new MemoryCache(new MemoryCacheOptions
 {
     SizeLimit = options.Value.SizeLimit
 })), keyProvider)
 {
 }
        public DistributedResponseCachingMiddleware(
            RequestDelegate next,
            IOptions <ResponseCachingOptions> options,
            ILoggerFactory loggerFactory,
            IResponseCachingPolicyProvider policyProvider,
            IResponseCache cache,
            IResponseCachingKeyProvider keyProvider)
            : base(next, options, loggerFactory, policyProvider, keyProvider)
        {
            var cacheFieldInfo = typeof(ResponseCachingMiddleware)
                                 .GetField(InternalCacheFieldName, BindingFlags.NonPublic | BindingFlags.Instance);

            if (cacheFieldInfo == null)
            {
                throw new Exception($"Failed to internal cache field named '{InternalCacheFieldName}'.");
            }

            cacheFieldInfo.SetValue(this, cache);
        }
        // for testing
        internal ResponseCachingMiddleware(
            RequestDelegate next,
            IOptions <ResponseCachingOptions> options,
            ILoggerFactory loggerFactory,
            IResponseCachingPolicyProvider policyProvider,
            IResponseCache cache,
            IResponseCachingKeyProvider keyProvider)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }
            if (policyProvider == null)
            {
                throw new ArgumentNullException(nameof(policyProvider));
            }
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }
            if (keyProvider == null)
            {
                throw new ArgumentNullException(nameof(keyProvider));
            }

            _next           = next;
            _options        = options.Value;
            _logger         = loggerFactory.CreateLogger <ResponseCachingMiddleware>();
            _policyProvider = policyProvider;
            _cache          = cache;
            _keyProvider    = keyProvider;
        }
Ejemplo n.º 8
0
        public EasyCachingResponseCachingMiddleware(
            RequestDelegate next,
            IOptions <ResponseCachingOptions> options,
            ILoggerFactory loggerFactory,
            IResponseCache cache,
            IResponseCachingPolicyProvider policyProvider,
            IResponseCachingKeyProvider keyProvider)
        {
            ArgumentCheck.NotNull(next, nameof(next));
            ArgumentCheck.NotNull(options, nameof(options));
            ArgumentCheck.NotNull(loggerFactory, nameof(loggerFactory));
            ArgumentCheck.NotNull(policyProvider, nameof(policyProvider));
            ArgumentCheck.NotNull(cache, nameof(cache));
            ArgumentCheck.NotNull(keyProvider, nameof(keyProvider));

            _next           = next;
            _options        = options.Value;
            _logger         = loggerFactory.CreateLogger <ResponseCachingMiddleware>();
            _policyProvider = policyProvider;
            _cache          = cache;
            _keyProvider    = keyProvider;
        }
Ejemplo n.º 9
0
        internal static ResponseCachingMiddleware CreateTestMiddleware(
            RequestDelegate next           = null,
            IResponseCache cache           = null,
            ResponseCachingOptions options = null,
            TestSink testSink = null,
            IResponseCachingKeyProvider keyProvider       = null,
            IResponseCachingPolicyProvider policyProvider = null)
        {
            if (next == null)
            {
                next = httpContext => Task.CompletedTask;
            }
            if (cache == null)
            {
                cache = new TestResponseCache();
            }
            if (options == null)
            {
                options = new ResponseCachingOptions();
            }
            if (keyProvider == null)
            {
                keyProvider = new ResponseCachingKeyProvider(new DefaultObjectPoolProvider(), Options.Create(options));
            }
            if (policyProvider == null)
            {
                policyProvider = new TestResponseCachingPolicyProvider();
            }

            return(new ResponseCachingMiddleware(
                       next,
                       Options.Create(options),
                       testSink == null ? (ILoggerFactory)NullLoggerFactory.Instance : new TestLoggerFactory(testSink, true),
                       policyProvider,
                       cache,
                       keyProvider));
        }
        public CustomResponseCachingMiddleware(RequestDelegate next, IOptions <ResponseCachingOptions> responseCachingOptions, IOptions <CustomResponseCachingOptions> overridableResponseCachingOptions, ILoggerFactory loggerFactory, IResponseCachingPolicyProvider policyProvider, IResponseCachingKeyProvider keyProvider) : base(next, responseCachingOptions, loggerFactory, policyProvider, keyProvider)
        {
            FieldInfo cacheFieldInfo = typeof(ResponseCachingMiddleware).GetField("_cache", BindingFlags.NonPublic | BindingFlags.Instance);

            cacheFieldInfo.SetValue(this, overridableResponseCachingOptions.Value.ResponseCacheFactory(responseCachingOptions));
        }
 public CustomResponseCachingMiddleware(RequestDelegate next, IOptions <ResponseCachingOptions> responseCachingOptions, IOptions <CustomResponseCachingOptions> overridableResponseCachingOptions, ILoggerFactory loggerFactory, IResponseCachingPolicyProvider policyProvider, IResponseCachingKeyProvider keyProvider) : base(next, responseCachingOptions, loggerFactory, policyProvider, overridableResponseCachingOptions.Value.ResponseCacheFactory(responseCachingOptions), keyProvider)
 {
 }