/// <summary> /// The event this handles fires after a document is published in the back office and the cache is updated. /// We render out the page and store it's HTML in the database for retrieval by the indexer. /// </summary> /// <param name="sender">Document being published</param> /// <param name="e">Event Arguments</param> /// <remarks> /// the indexer thread doesn't always access to a fully initialised umbraco core to do the rendering, /// whereas this event always should, hence this method rather than doing both rendering and indexing /// in the same thread /// </remarks> private void ContentAfterUpdateDocumentCache(Document sender, DocumentCacheEventArgs e) { if (sender == null || sender.Id < 1) { return; } var id = sender.Id; // get config and check we're enabled and good to go if (!CheckConfig()) { return; } // this can take a while... Library.SetTimeout(Config.Instance.GetByKey("ScriptTimeout")); var nodeTypeAlias = sender.ContentType.Alias; var renderer = Manager.Instance.DocumentRendererFactory.CreateNew(nodeTypeAlias); string fullHtml; if (renderer.Render(id, out fullHtml)) { HtmlCache.Store(id, ref fullHtml); } else { HtmlCache.Remove(id); } }
protected override bool Render(string cacheKey, TextWriter writer, RenderRenderingArgs args) { //Check if the Timeout key is in the cache key; if not, try the base/Sitecore version if (!cacheKey.Contains(Settings.TimeoutRenderingKey)) { return(base.Render(cacheKey, writer, args)); } //Check if the caching site exists; if not, try the base/Sitecore version SiteContext cachingSite = SiteContext.GetSite(Settings.CachingSite); if (cachingSite == null) { return(base.Render(cacheKey, writer, args)); } //Check if an HTML cache exists for the caching site and that the HTML is present; if not, try the base/Sitecore version HtmlCache htmlCache = CacheManager.GetHtmlCache(cachingSite); string html = htmlCache?.GetHtml(cacheKey); if (html == null) { return(base.Render(cacheKey, writer, args)); } //If everything is good, write the HTML from the cache writer.Write(html); return(true); }
protected override void DoProcess(ClearOutputCachesArgs args) { foreach (SiteInfo siteInfo in Sitecore.Configuration.Factory.GetSiteInfoList()) { // Log.Info(this + " : checking siteInfo for " + siteInfo.Name, this); if (!siteInfo.CacheHtml) { // Log.Info(this + " : CacheHtml false; continue : " + siteInfo.Name, this); continue; } SiteContext siteContext = Sitecore.Configuration.Factory.GetSite(siteInfo.Name); Assert.IsNotNull(siteContext, "siteContext: " + siteInfo.Name); HtmlCache htmlCache = CacheManager.GetHtmlCache(siteContext); if (htmlCache == null || htmlCache.InnerCache.Count < 1 || (htmlCache.InnerCache.Count < 2 && htmlCache.InnerCache.ContainsKey(args.LastClearedKey))) { Log.Info(this + " : no html cache, cache count less than one, or only contains last cleared key : " + siteInfo.Name + " : " + htmlCache, this); continue; } Log.Info(this + " : AddOutputCacheSite! : " + siteInfo.Name, this); args.AddOutputCacheSite(new OutputCacheSite( siteContext, htmlCache, args.LastClearedKey)); } }
/// <summary> /// Delete HTML on unpublish /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void ContentServiceUnPublished(global::Umbraco.Core.Publishing.IPublishingStrategy sender, global::Umbraco.Core.Events.PublishEventArgs <IContent> e) { if (!CheckConfig()) { return; } foreach (var content in e.PublishedEntities.Where(Content => Content.Id > 0)) { HtmlCache.Remove(content.Id); } }
/// <summary> /// Make sure HTML is deleted from storage when the node is moved to trash /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void ContentServiceTrashed(IContentService sender, global::Umbraco.Core.Events.MoveEventArgs <IContent> e) { if (!CheckConfig()) { return; } if (e.Entity.Id > 0) { HtmlCache.Remove(e.Entity.Id); } }
public OutputCacheSite( SiteContext siteContext, HtmlCache htmlCache, string lastClearedKey) { Assert.ArgumentNotNull(siteContext, "siteContext"); Assert.ArgumentNotNull(htmlCache, "htmlCache"); Assert.ArgumentNotNullOrEmpty(lastClearedKey, "lastClearedKey"); this.SiteContext = siteContext; this.HtmlCache = htmlCache; this.LastClearedKey = lastClearedKey; }
/// <summary> /// Make sure HTML is deleted from storage when the node is deleted /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void ContentServiceDeleted(IContentService sender, global::Umbraco.Core.Events.DeleteEventArgs <IContent> e) { //FIXME: what happens when entire trees are deleted? does this get called multiple times? if (!CheckConfig()) { return; } foreach (var content in e.DeletedEntities.Where(Content => Content.Id > 0)) { HtmlCache.Remove(content.Id); } }
public bool getHtmlCache(string template, string tag, ref List <string> types, ref List <int> heads, ref List <int> ends , ref List <string> templateStatic, ref List <string> innerTemplateList) { Dictionary <string, HtmlCache> out1 = null; if (strHtml.TryGetValue(template, out out1)) { HtmlCache out2 = null; if (strHtml[template].TryGetValue(tag, out out2)) { return(true); } } return(false); }
private void OnTimerProcess(object sender, ElapsedEventArgs e) { DateTime now = DateTime.Now; Predicate <CacheBlock> pre = x => { if ((now - x.CacheTime).TotalMilliseconds > Timeout) { return(true); } return(false); }; HtmlCache.RemoveAll(pre); MarkdownCache.RemoveAll(pre); }
protected override void AddHtmlToCache(string cacheKey, string html, RenderRenderingArgs args) { //Check if the Timeout key is in the cache key; if not, try the base/Sitecore version if (!cacheKey.Contains(Settings.TimeoutRenderingKey)) { base.AddHtmlToCache(cacheKey, html, args); return; } //Check if the Timeout value is present and a valid TimeSpan; if not, try the base/Sitecore version bool timeoutValue = TimeSpan.TryParse(args.Rendering.RenderingItem.InnerItem[Settings.TimeoutRenderingParam], out _); if (!timeoutValue) { base.AddHtmlToCache(cacheKey, html, args); return; } //Check if the caching site exists; if not, try the base/Sitecore version SiteContext cachingSite = SiteContext.GetSite(Settings.CachingSite); if (cachingSite == null) { base.AddHtmlToCache(cacheKey, html, args); return; } //Check if the HTML cache is available in the caching site; if not, try the base/Sitecore version HtmlCache htmlCache = CacheManager.GetHtmlCache(cachingSite); if (htmlCache == null) { base.AddHtmlToCache(cacheKey, html, args); return; } //If everything is good, set the timeout based on the rendering parameter and put the HTML in the caching site TimeSpan timeout = GetTimeout(args); htmlCache.SetHtml(cacheKey, html, timeout); }
public bool setHtmlCache(string template, string tag, ref List <string> types, ref List <int> heads, ref List <int> ends , ref List <string> templateStatic, ref List <string> innerTemplateList) { if (!strHtml.ContainsKey(template)) { strHtml.Add(template, new Dictionary <string, HtmlCache>()); } if (!strHtml[template].ContainsKey(tag)) { HtmlCache cache = new HtmlCache(); cache.types = types; cache.heads = heads; cache.ends = ends; cache.templateStatic = templateStatic; cache.innerTemplateList = innerTemplateList; strHtml[template].Add(tag, cache); return(true); } return(false); }
/// <summary> /// Render a single document to cache /// </summary> /// <param name="Content"></param> protected static void RenderNodeToCache(IContent Content) { if (Content != null && Content.Trashed != true && Content.Published) { /*if (doc.PublishWithResult(user)) * { * umbraco.library.UpdateDocumentCache(doc.Id); * }*/ var nodeTypeAlias = Content.ContentType.Alias; var renderer = Manager.Instance.DocumentRendererFactory.CreateNew(nodeTypeAlias); string fullHtml; if (renderer.Render(Content.Id, out fullHtml)) { HtmlCache.Store(Content.Id, ref fullHtml); } else { HtmlCache.Remove(Content.Id); } } }
public bool setHtmlCache(string template, string tag, ref List<string> types, ref List<int> heads, ref List<int> ends , ref List<string> templateStatic, ref List<string> innerTemplateList) { if (!strHtml.ContainsKey(template)) { strHtml.Add(template, new Dictionary<string, HtmlCache>()); } if (!strHtml[template].ContainsKey(tag)) { HtmlCache cache = new HtmlCache(); cache.types = types; cache.heads = heads; cache.ends = ends; cache.templateStatic = templateStatic; cache.innerTemplateList = innerTemplateList; strHtml[template].Add(tag, cache); return true; } return false; }
/// <summary> /// Initializes a new instance of the <see cref="HtmlCacheProvider" /> class. /// </summary> /// <param name="site">The site context.</param> public HtmlCacheProvider(SiteContext site) { this.htmlCache = site.ValueOrDefault(Sitecore.Caching.CacheManager.GetHtmlCache); Assert.IsNotNull(this.htmlCache, "htmlCache can not be null"); }
protected override bool GetHtml(out string fullHtml) { LogHelper.Debug <CacheIndexer>($"FullTextIndexing: CacheIndexer.GetHtml() for {CurrentContent.Name} [{CurrentContent.Id}]..."); return(HtmlCache.Retrieve(CurrentContent.Id, out fullHtml)); }