示例#1
0
        protected internal virtual IHtmlString RenderView(ViewPosition viewPosition)
        {
            Func<IHtmlString> renderView = () => this.RenderView(viewPosition.ViewName, PageContext.GetPositionViewData(viewPosition.PagePositionId), viewPosition.ToParameterDictionary(), false);
            if (viewPosition.EnabledCache)
            {
                var cacheKey = string.Format("View OutputCache - Full page name:{0};Raw request url:{1};PagePositionId:{2};ViewName:{3};LayoutPositionId:{4}"
                , PageContext.PageRequestContext.Page.FullName, PageContext.ControllerContext.HttpContext.Request.RawUrl, viewPosition.PagePositionId, viewPosition.ViewName, viewPosition.LayoutPositionId);
                var cacheItemPolicy = viewPosition.OutputCache.ToCachePolicy();
                return this.PageContext.PageRequestContext.Site.ObjectCache().GetCache<IHtmlString>(cacheKey,
                          renderView,
                      cacheItemPolicy);
            }

            else
            {
                return renderView();
            }
        }
示例#2
0
        protected virtual IHtmlString RenderView(ViewPosition viewPosition)
        {
            string cacheKey = null;
            var site = PageContext.PageRequestContext.Site;
            if (viewPosition.EnabledCache)
            {
                cacheKey = GetOutputCacheKey(PageContext.ControllerContext.HttpContext, PageContext.PageRequestContext.Page, viewPosition);
                var outputCache = PageContext.PageRequestContext.Site.ObjectCache().Get(cacheKey);
                if (outputCache != null)
                {
                    return new HtmlString(outputCache.ToString());
                }
            }
            var htmlString = RenderView(viewPosition.ViewName, Page_Context.Current.GetPositionViewData(viewPosition.PagePositionId), viewPosition.ToParameterDictionary(), false);

            if (!string.IsNullOrEmpty(cacheKey))
            {
                PageContext.PageRequestContext.Site.ObjectCache().Add(cacheKey, htmlString, viewPosition.OutputCache.ToCachePolicy());
            }

            return htmlString;
        }