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?
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!
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.
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 theContentCacheRefresher.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?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é
Anyone in the future in this situation.
We created our own
OurCacheRefresher
based on theJsonCacheRefresherBase<>
class.Now you can trigger this by running
Which will call the
OurCacheRefresher.CacheUpdated
event. You can subscribe to this from a component like you would with aContentCacheRefresher
.You need to trigger the
DistributedCache.RefreshAll
on your backoffice server. And theOurCacheRefresher.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 theIUmbracoContextFactory.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.
is working on a reply...