Copied to clipboard

Flag this post as spam?

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


  • Roy Berris 89 posts 577 karma points c-trib
    Dec 17, 2021 @ 07:39
    Roy Berris
    0

    Replica not receiving ContentCacheRefresher.CacheUpdated when using IContentService.SaveAndPublish

    So we have a load balancing set-up running. The replica's are registered to refresh content with our own ICacheRefresher when the ContentCacheRefresher.CacheUpdated is called. It verifies which items are updated and if the right items are there we refresh. This works fine when clicking "Save and Publish" in the backoffice.

    But for some reason this is not triggered when save and publishing from the IContentService. I ran a debugger on the replica and it never enters the event.

    Is the IContentService not responsible for sending a cache refresh? And how do we trigger it programmatically with a specific payload?

  • Corné Hoskam 80 posts 587 karma points MVP 3x c-trib
    Dec 17, 2021 @ 07:59
    Corné Hoskam
    0

    Hi Roy,

    I believe your assumption is correct, that the IContentService is not responsible for sending a cash refresh across a load balanced server by default. Perhaps hooking into the OnPublished event using an IComponent, from which you can trigger an DistributedCache refresh across multiple servers!

    Hope this helped

    Corné

  • Roy Berris 89 posts 577 karma points c-trib
    Dec 17, 2021 @ 12:50
    Roy Berris
    100

    Anyone in the future in this situation.

    We created our own OurCacheRefresher based on the JsonCacheRefresherBase<> class.

    Now you can trigger this by running

    var distributedCache = new DistributedCache();
    distributedCache.RefreshAll(OurCacheRefresher.UniqueId)
    

    Which will call the OurCacheRefresher.CacheUpdated event. You can subscribe to this from a component like you would with a ContentCacheRefresher.

    You need to trigger the DistributedCache.RefreshAll on your backoffice server. And the OurCacheRefresher.CacheUpdated will be called on every replica.


    This is all common knowledge from the documentation. Our problem was that we were calling this inside of a using statement with the IUmbracoContextFactory.EnsureUmbracoContext. For whatever reason it does not work here. It might be a bug, it might be intended.

    I was calling it from a non-web context. Where it does seem to be possible to do this. Instead I called an API endpoint that I created from the non-web context to create a web context. In this scope you can successfully refresh the cache on every server.

Please Sign in or register to post replies

Write your reply to:

Draft