Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 120 posts 448 karma points
    Feb 27, 2019 @ 13:29
    Tom
    1

    ContentService.Published - Can't get node from contentcache

    Hi,

    So I'm catching the Published event just like in the documentation - https://our.umbraco.com/documentation/reference/events/contentservice-events

    But when trying to do something like this on a newly created node:

    var publishedNode = UmbracoContext.Current.ContentCache.GetById(node.Id);
    

    I get a null back from the ContentCache.GetById?

    Why is the node not in the content cache?

  • Sören Deger 733 posts 2844 karma points c-trib
    Feb 27, 2019 @ 13:40
    Sören Deger
    0

    Hi Tom, is the node published and the nodeId correct?

    If yes, maybe there is an cache issue. Republish entire site and try again.

    Best, Sören

  • Tom 120 posts 448 karma points
    Feb 27, 2019 @ 13:54
    Tom
    0

    Yes the node id comes from PublishEventArgs parameter in the Published event.

    Shouldn't the content cache get updated before hitting the Published event?

  • Sören Deger 733 posts 2844 karma points c-trib
    Feb 27, 2019 @ 14:00
    Sören Deger
    0

    Hi Tom, the content cache is updated if the node is published. Can you show me more code of the specific method?

  • Tom 120 posts 448 karma points
    Feb 27, 2019 @ 14:05
    Tom
    0
     private void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs<IContent> args)
     {
        foreach (var node in args.PublishedEntities)
        {
    
            if (node.ContentType.Alias == "newsItem")
            {
    
                var publishedNode = UmbracoContext.Current.ContentCache.GetById(node.Id);
    
                var nodeUrl = new Uri(helper.UrlAbsolute(node.Id)); }}}
    

    Here publishedNode is null, if its the first time publishing the node.

Please Sign in or register to post replies

Write your reply to:

Draft