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 22, 2018 @ 15:57
    Jay
    0

    PageCacheRefresher and MessageType.RefreshById no longer works with UmbracoContext.Current V7.12.3

    I've been trying to hook into the Distributed call events using

    CacheRefresherBase<PageCacheRefresher>.CacheUpdated += this.PageCacheRefresherCacheUpdated;
    

    and then using

    private void PageCacheRefresherCacheUpdated(PageCacheRefresher sender, CacheRefresherEventArgs e)
            {
                if (e?.MessageObject != null)
                {
                    if (e.MessageType == MessageType.RefreshById)
                    {
                        var item = UmbracoContext.Current.ContentCache.GetById((int)e.MessageObject);
    
                    }
                }
            }
    

    But UmbracoContext.Current is always null when this gets hits in the Slave machine. Has this been changed in the new version of Umbraco V7.12.3?

    I remember it used to work before in an older version

    Thanks

  • Jay 425 posts 652 karma points
    Nov 22, 2018 @ 15:59
    Jay
    0

    Been digging around, used to work like in this example to call ContentCache https://github.com/Shazwazza/Articulate/blob/master/src/Articulate/UmbracoEventHandler.cs#L115

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Nov 22, 2018 @ 18:33
    Søren Gregersen
    0

    The call is initiated via a scheduled task (AFAIK), and you can't be sure that the umbraco context is available, when there is no webrequest involved.

    Take a look at https://github.com/Shazwazza/Articulate/blob/master/src/Articulate/UmbracoEventHandler.cs#L109 ;)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 12x admin c-trib
    Nov 23, 2018 @ 08:59
    Jeavon Leopold
    1

    This is due to this breaking change in v7.8.0+ https://issues.umbraco.org/issue/U4-10150

  • Jay 425 posts 652 karma points
    Nov 23, 2018 @ 09:25
    Jay
    0

    Thanks Jeavon. No wonder

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 10x admin c-trib
    Nov 23, 2018 @ 12:14
    Dave Woestenborghs
    100

    Hi,

    You can create your own fake umbracocontext and use that if you need it

    var httpContext = new HttpContextWrapper(HttpContext.Current ?? new HttpContext(new SimpleWorkerRequest("temp.aspx", "", new StringWriter())));
    
    var umbContext = UmbracoContext.EnsureContext(
                httpContext,
                ApplicationContext.Current,
                new WebSecurity(httpContext, ApplicationContext.Current),
                UmbracoConfig.For.UmbracoSettings(),
                UrlProviderResolver.Current.Providers,
                false);
    

    Dave

  • Jay 425 posts 652 karma points
    Nov 26, 2018 @ 14:19
    Jay
    0

    Thanks Dave, will try that out

  • Jay 425 posts 652 karma points
    Nov 26, 2018 @ 15:06
    Jay
    0

    Seems to work. Thanks Dave

  • 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