We have added MVC output caching to our Umbraco site. Each page is cache for some period of time. To prevent stale pages we have tied into the Umbraco ContentService and FileService events to clear the cache.
We are in a load balanced environment using Webserver A and Webserver B to serve content and Admin Server A as the back-end office.
The problem we are having is that when a publish occurs from Admin Server A it is not firing the events to clear the cache on either webserver. The cache is cleared on the Admin server.
Our current work around is to then go to the webserver and publish the content again there. When doing that, both webserver caches clear.
I'm wondering why the Admin Server publish is not triggering the events for the webservers when doing the same thing directly on one of the webservers triggers the event for both web servers.
Here is the code we are using to clear the memory cache:
Essentially your events aren't happening on the other servers, only on the admin server, and then Umbraco (if configured correctly) should be telling the other servers to 'refresh their cache' (and this won't trigger the actual events to occur again)
Umbraco uses 'ICacheRefreshers': and classes that implement this interface take responsibility for updating the Umbraco Cache for the type of item across other configured load balanced servers.
You can implement your own custom ICacheRefresher but you may not need to...
... this is because the existing Cacherefreshers should fire an event 'CacheUpdated' on each of the load balanced servers.
So you could hook into the
PageCacheRefresher.CacheUpdated
and
MediaCacheRefresher.CacheUpdated
events to clear your output caching.
But another reason why you may not need to do this is Umbraco kind of has a basic output caching mechanism already built in that gets cleared across load balanced servers whenever you publish.
If the items you want to cache are in a partial view, then just write them out in your template as:
Html.CachedPartial("partialName", model, 3600)
where 3600 is the length of time to cache, there are further overloads to indicate whether to cache by page or cache by member.
Thanks for the response Marc. We are modifying our staging environment now so that it better reflects production (currently staging does not use the proper dedicated admin server for load balancing).
Once we have made those changes I'll try your recommendations there and get back to you on the results in a few days.
Back Office Not Clearing Webserver Cache
We have added MVC output caching to our Umbraco site. Each page is cache for some period of time. To prevent stale pages we have tied into the Umbraco ContentService and FileService events to clear the cache.
We are in a load balanced environment using Webserver A and Webserver B to serve content and Admin Server A as the back-end office.
The problem we are having is that when a publish occurs from Admin Server A it is not firing the events to clear the cache on either webserver. The cache is cleared on the Admin server.
Our current work around is to then go to the webserver and publish the content again there. When doing that, both webserver caches clear.
I'm wondering why the Admin Server publish is not triggering the events for the webservers when doing the same thing directly on one of the webservers triggers the event for both web servers.
Here is the code we are using to clear the memory cache:
Thanks for any assistance.
Hi David
Which strategy are you using for load balancing with Umbraco ?
Flexible or Traditional ?
https://our.umbraco.org/documentation/getting-started/setup/server-setup/load-balancing/
Essentially your events aren't happening on the other servers, only on the admin server, and then Umbraco (if configured correctly) should be telling the other servers to 'refresh their cache' (and this won't trigger the actual events to occur again)
Umbraco uses 'ICacheRefreshers': and classes that implement this interface take responsibility for updating the Umbraco Cache for the type of item across other configured load balanced servers.
https://github.com/umbraco/Umbraco-CMS/blob/75c2b07ad3a093b5b65b6ebd45697687c062f62a/src/umbraco.interfaces/ICacheRefresher.cs
For example here is an implementation responsible for clearing the cache of dictionary items when they are updated:
https://github.com/umbraco/Umbraco-CMS/blob/75c2b07ad3a093b5b65b6ebd45697687c062f62a/src/Umbraco.Web/Cache/DictionaryCacheRefresher.cs
You can implement your own custom ICacheRefresher but you may not need to...
... this is because the existing Cacherefreshers should fire an event 'CacheUpdated' on each of the load balanced servers.
So you could hook into the PageCacheRefresher.CacheUpdated and MediaCacheRefresher.CacheUpdated
events to clear your output caching.
But another reason why you may not need to do this is Umbraco kind of has a basic output caching mechanism already built in that gets cleared across load balanced servers whenever you publish.
If the items you want to cache are in a partial view, then just write them out in your template as:
where 3600 is the length of time to cache, there are further overloads to indicate whether to cache by page or cache by member.
https://our.umbraco.org/documentation/reference/templating/mvc/partial-views#caching
if that helps
regards
Marc
Thanks for the response Marc. We are modifying our staging environment now so that it better reflects production (currently staging does not use the proper dedicated admin server for load balancing).
Once we have made those changes I'll try your recommendations there and get back to you on the results in a few days.
What happened? Did you solve this?
is working on a reply...