Copied to clipboard

Flag this post as spam?

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


  • Jay 425 posts 652 karma points
    Nov 01, 2019 @ 11:57
    Jay
    0

    PageCacheRefresher in Umbraco V8

    Anyone knows what's the new PageCacheRefresher events on distributed servers on the new Umbraco V8?

    Thanks

  • Marc Goodson 2157 posts 14435 karma points MVP 9x c-trib
    Nov 01, 2019 @ 20:44
    Marc Goodson
    102

    Hi JLon

    I think you might be after this?

    public class RegisteringCacheUpdatedEvents : IUserComposer
    {
        public void Compose(Umbraco.Core.Composing.Composition composition)
        {
            ContentCacheRefresher.CacheUpdated += ContentCacheRefresher_CacheUpdated;
            MediaCacheRefresher.CacheUpdated += MediaCacheRefresher_CacheUpdated;
        }
    
        private void MediaCacheRefresher_CacheUpdated(MediaCacheRefresher sender, CacheRefresherEventArgs e)
        {
           //media cache updated
        }
    
        private void ContentCacheRefresher_CacheUpdated(ContentCacheRefresher sender, CacheRefresherEventArgs e)
        {
            //content cache updated!
        }
    }
    

    regards

    Marc

  • Jay 425 posts 652 karma points
    Nov 04, 2019 @ 12:00
    Jay
    0

    Thanks Marc :)

  • Jay 425 posts 652 karma points
    Dec 04, 2019 @ 15:44
    Jay
    0

    Hey Marc,

    Do you also know if there's a way we can detect the type of the event.

    Eg if it's a Save and Publish or even if it's Unpublishing on a content?

    When I debug through the e.MessageObject within the ContentCacheRefresher_CacheUpdated()

    It keeps coming back as MessageType.RefreshByPayload for Save and Publish or Unpublishing

    Thanks

  • Marc Goodson 2157 posts 14435 karma points MVP 9x c-trib
    Dec 07, 2019 @ 08:22
    Marc Goodson
    2

    Hi Jeric

    I can't find a good example of this, and I'm guessing a little but I think knowing the MessageType is RefreshByPayload, means you can cast the MessageObject into they type of Payload, and loop through each Payload, and it's ChangeType to determine a little about what is going on.

    Have a look at the Examine ContentCacheRefresherUpdated event handling implementation in the core:

    https://github.com/umbraco/Umbraco-CMS/blob/13488be0a3280c966ca5115c1cf75cc1979e5819/src/Umbraco.Web/Search/ExamineComponent.cs#L133

      foreach (var payload in (ContentCacheRefresher.JsonPayload[])args.MessageObject)
                {
                    if (payload.ChangeTypes.HasType(TreeChangeTypes.Remove))
                    {
                        // delete content entirely (with descendants)
                        //  false: remove entirely from all indexes
                        DeleteIndexForEntity(payload.Id, false);
                    }
    

    The ChangeTypes enum is here;

    public enum TreeChangeTypes : byte
    {
        None = 0,
    
        // all items have been refreshed
        RefreshAll = 1,
    
        // an item node has been refreshed
        // with only local impact
        RefreshNode = 2,
    
        // an item node has been refreshed
        // with branch impact
        RefreshBranch = 4,
    
        // an item node has been removed
        // never to return
        Remove = 8,
    }
    

    So you should be able to tell the difference between an Unpublish and a Publish.

    regards

    Marc

  • Jay 425 posts 652 karma points
    Dec 11, 2019 @ 12:19
    Jay
    0

    Thanks Marc

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies