Copied to clipboard

Flag this post as spam?

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


  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Sep 13, 2019 @ 05:43
    Nathan Woulfe
    0

    PageCacheRefresher events on distributed servers

    Hi legends

    Trying to debug an issue where cached items aren't updated on distributed servers - we push some custom data into cache to avoid some relatively complex lookups per request. Works fine on the primary server, but is never updated on secondary servers.

    Event handler looks like this:

    PageCacheRefresher.CacheUpdated += (sender, args) =>
    {
        IContent doc;
        if (args.MessageType == MessageType.RefreshByInstance)
        {
            doc = args.MessageObject as IContent;
        }
        else if (args.MessageType == MessageType.RefreshById)
        {
            doc = ApplicationContext.Current.Services.ContentService.GetById((int)args.MessageObject);
        }
        else {
            return;
        }
    
        // do stuff with the IContent item - usually using a property value to invalidate a cached item, which we stored when it was requested and generated
    }
    

    My understanding is that on the server generating the event, args.MessageObject is the IContent item, on the listening servers it's the ID of the item, hence the lookup for the node.

    From what I can tell though, this never executes anywhere other than the primary server.

    Also curious - is UmbracoContext available on the secondary server when the event is raised?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Sep 13, 2019 @ 11:09
    Dave Woestenborghs
    0

    Hi Nathan,

    What I would do is to check if the cache instruction message is written to the database when you publish.

    You can check the in the umbracoCacheInstruction database. You can analyse the json instruction if you want to see what is being instructed to the cache.

    With the last id you can check if it is processed on the secondary server.

    There should be a file in App_Data\TEMP\DistCache\

    The content of that file is the last cache instruction that is processed. That should be in sync with the database.

    If that is working I would suggest to put some logging in your cache refresh handler to see what is going on.

    You can also install this package of mine : https://our.umbraco.com/packages/backoffice-extensions/loadbalancing-information-dashboard/

    It will give you some info about your configuration and which servers are registered.

    Dave

  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Sep 15, 2019 @ 00:44
    Nathan Woulfe
    0

    Thanks Dave, will try this on Monday.

    We'd been subscribing to the ContentService OnPublish event (for months, if not years) to deal with caching global properties in a custom model, and hadn't noticed the model was being cached until the pool recycled (nightly). Made some other changes, this issue surfaced, now scratching my head to solve it... Good times!

Please Sign in or register to post replies

Write your reply to:

Draft