public async Task InvokeAsync(HttpContext context)
 {
     if (!_options.DoesRequestQualify(context))
     {
         await _next(context);
     }
     else if (_cache.TryGetValue(context.Request.Host + context.Request.Path, out OutputCacheResponseEntry entry) && entry.IsCached(context, out OutputCacheResponse item))
     {
         await ServeFromCacheAsync(context, item);
     }
     else
     {
         await ServeFromMvcAndCacheAsync(context, entry);
     }
 }
Example #2
0
 public async Task InvokeAsync(HttpContext context)
 {
     if (!_options.DoesRequestQualify(context))
     {
         await _next(context);
     }
     else if (_cache.TryGetValue(context, out OutputCacheResponse response))
     {
         await ServeFromCacheAsync(context, response);
     }
     else
     {
         await ServeFromMvcAndCacheAsync(context);
     }
 }
        public async Task InvokeAsync(HttpContext context)
        {
            if (!_options.DoesRequestQualify(context))
            {
                await _next(context);
            }
            else
            {
                JObject jObject = null;
                if (context.Request.ContentType != null && context.Request.ContentType.Contains("application/json"))
                {
                    try
                    {
                        context.Request.EnableRewind();

                        using (var reader = new StreamReader(context.Request.Body, Encoding.UTF8, true, 1024, true))
                        {
                            string strRequestBody = await reader.ReadToEndAsync();

                            jObject = JObject.Parse(strRequestBody);
                            context.Request.Body.Position = 0;
                        }

                        context.Request.Body.Position = 0;
                    }
                    catch
                    {
                        // ignored
                    }
                }

                if (_cache.TryGetValue(context, jObject, out OutputCacheResponse response))
                {
                    await ServeFromCacheAsync(context, response);
                }
                else
                {
                    await ServeFromMvcAndCacheAsync(context, jObject);
                }
            }
        }