/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } } }