/// <summary> /// Render the html and adds it to the cache. /// </summary> /// <param name="helper">The helper.</param> /// <param name="partialRequest">The partial request.</param> /// <param name="content">The content.</param> /// <param name="templateModel">The template model.</param> /// <param name="settings">The settings.</param> /// <param name="cacheKey">The cache key.</param> protected virtual void RenderAndAddToCache(HtmlHelper helper, PartialRequest partialRequest, IContent content, TemplateModel templateModel, ICacheableSettings settings, string cacheKey) { using (var cacheWriter = new StringWriter()) { var currentWriter = helper.ViewContext.Writer; helper.ViewContext.Writer = cacheWriter; DefaultRenderer.Render(helper, partialRequest, content, templateModel); var html = cacheWriter.ToString(); currentWriter.Write(html); helper.ViewContext.Writer = currentWriter; if (helper.ViewContext.HttpContext.Error == null) { InsertToCache(html); } } void InsertToCache(string html) { if (settings.MaxTimeInCache == TimeSpan.Zero) { Cache.Insert(cacheKey, html, new CacheEvictionPolicy(null, MasterCacheKeys)); } else { Cache.Insert(cacheKey, html, new CacheEvictionPolicy(settings.MaxTimeInCache, CacheTimeoutType.Absolute, null, MasterCacheKeys)); } } }
/// <summary> /// Tries to render the HTML from cache, falls back to the default renderer if the content is not cacheable. /// </summary> /// <param name="htmlHelper">The HTML helper.</param> /// <param name="partialRequest">The partial request.</param> /// <param name="contentData">The content data.</param> /// <param name="templateModel">The template model.</param> public void RenderFromCache(HtmlHelper htmlHelper, PartialRequest partialRequest, IContentData contentData, TemplateModel templateModel) { if (SettingsService.TryGetSettingsFromContentData(contentData, out ICacheableSettings settings) && IsCacheEnabled() && contentData is IContent content) { RenderFromOrAddToCache(htmlHelper, partialRequest, content, templateModel, settings); } else { DefaultRenderer.Render(htmlHelper, partialRequest, contentData, templateModel); } bool IsCacheEnabled() { if (PageEditing.PageIsInEditMode) { return(settings.IsCacheEnabled && settings.CacheInCmsEditor); } return(settings.IsCacheEnabled); } }
public void RenderScene(DrawEventArgs args) { renderer.Render(Renderer); }