Copied to clipboard

Flag this post as spam?

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


  • Jeric Yuen 334 posts 508 karma points
    Nov 22, 2018 @ 15:57
    Jeric Yuen
    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

  • Jeric Yuen 334 posts 508 karma points
    Nov 22, 2018 @ 15:59
    Jeric Yuen
    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 355 posts 1468 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 3008 posts 13221 karma points MVP 7x 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

  • Jeric Yuen 334 posts 508 karma points
    Nov 23, 2018 @ 09:25
    Jeric Yuen
    0

    Thanks Jeavon. No wonder

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x 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

  • Jeric Yuen 334 posts 508 karma points
    Nov 26, 2018 @ 14:19
    Jeric Yuen
    0

    Thanks Dave, will try that out

  • Jeric Yuen 334 posts 508 karma points
    Nov 26, 2018 @ 15:06
    Jeric Yuen
    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