Skip to main content

Handling Umbraco Events After Deploy Operations

I had a question from an partner Umbraco raised for me this week, that's available at this forum topic.

They had some code running in a notification handler running when dictionary items were saved, and found this wasn't firing when the item was saved following an Umbraco Deploy operation.

I responded that this is actually expected behaviour - as Deploy supresses events being fired on individual save and publish events when transferring items. This implementation decision was made I understand for performance reasons. In the back-office, the usual case for a save of an item is one-at-a-time, but with a deployment, there could be hundreds of updates within an operation.

However, what if you do want to run some code on the save of some Umbraco data, even if this is happening as part of a Deploy operation?

There's an option here using cache refresher notifications. Not all events are suppressed by Umbraco Deploy - some that are batched up and fired after the deploy operation is completed are those related to refreshing the Umbraco cache. These are necessary to ensure that in load balanced environments, all instances get their cache updated in the case for example of a content item being saved. When they run, they fire off notifications.

The following gist shows how one of these notifications can be hooked into and some custom code run.

There are a couple of checks in place to make sure we are handling the appropriate event - in this case a cache refresh of a single dictionary item. I've also ensured it only runs only once in load balanced environments.

Comments