Ejemplo n.º 1
0
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            if (_originalWriter == null || DisableMoth || !(filterContext.RequestContext.HttpContext.Response.Output is HtmlTextWriter))
            {
                return;
            }

            // switch de writer terug
            HtmlTextWriter cacheWriter = (HtmlTextWriter)SwitchWriterMethod.Invoke(HttpContext.Current.Response, new object[] { _originalWriter });
            var            textWritten = cacheWriter.InnerWriter.ToString();

            // execute all executors that allow for caching
            foreach (var executor in Executors.Where(e => e.AllowCaching == AllowCachingEnum.Yes))
            {
                textWritten = executor.Replace(filterContext.HttpContext, filterContext.Controller.ControllerContext, textWritten);
            }

            // cachen voor de volgende keer?
            if (OutputCaching && CacheProvider.Enable.PageOutput && filterContext.Exception == null)
            {
                var result = new OutputCacheItem()
                {
                    Content     = textWritten,
                    ContentType = filterContext.Result is ContentResult ? ((ContentResult)filterContext.Result).ContentType : ""
                };

                CacheProvider.Store(_cacheKey, result, CacheProvider.CacheDurations.PageOutput);
            }

            foreach (var executor in Executors.Where(e => e.AllowCaching == AllowCachingEnum.No))
            {
                textWritten = executor.Replace(filterContext.HttpContext, filterContext.Controller.ControllerContext, textWritten);
            }

            // output naar response stream
            filterContext.HttpContext.Response.Write(textWritten);
        }
Ejemplo n.º 2
0
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            if (_originalWriter == null || DisableMoth || !(filterContext.RequestContext.HttpContext.Response.Output is HtmlTextWriter))
            {
                return;
            }

            // switch de writer terug
            HtmlTextWriter cacheWriter = (HtmlTextWriter)SwitchWriterMethod.Invoke(HttpContext.Current.Response, new object[] { _originalWriter });
            var textWritten = cacheWriter.InnerWriter.ToString();

            // execute all executors that allow for caching
            foreach (var executor in Executors.Where(e => e.AllowCaching == AllowCachingEnum.Yes))
            {
                textWritten = executor.Replace(filterContext.HttpContext, filterContext.Controller.ControllerContext, textWritten);
            }

            // cachen voor de volgende keer?
            if (OutputCaching && CacheProvider.Enable.PageOutput && filterContext.Exception == null)
            {
                var result = new OutputCacheItem()
                    {
                        Content = textWritten,
                        ContentType = filterContext.Result is ContentResult ? ((ContentResult) filterContext.Result).ContentType : ""
                    };

                CacheProvider.Store(_cacheKey, result, CacheProvider.CacheDurations.PageOutput);
            }

            foreach (var executor in Executors.Where(e => e.AllowCaching == AllowCachingEnum.No))
            {
                textWritten = executor.Replace(filterContext.HttpContext, filterContext.Controller.ControllerContext, textWritten);
            }

            // output naar response stream
            filterContext.HttpContext.Response.Write(textWritten);
        }