Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
This is the first time I'm using Umbraco events in Umbraco 8.
I have subscribed to the ContentService.Saved event and this is firing correctly.
However when a new node is created when I try to use the umbraco helper to retrive it as IPublished content, but I always get null. Why is this?
As I understand it this event fires AFTER the new node has been saved, so I don't understand why I get NULL.
Here is my code, any ideas?
public class SubscribeToSaveEventComposer : ComponentComposer<SubscribeToSaveEventComponent>
public class SubscribeToSaveEventComponent : IComponent
public void Initialize()
ContentService.Saved += ContentService_Saved;
ContentService.Saving += ContentService_Saving;
private void ContentService_Saved(IContentService sender, ContentSavedEventArgs e)
foreach (var node in e.SavedEntities)
if (node.ContentType.Alias == "clientContainer")
//Why is Brand New Node = NULL
var brandNewNode = Umbraco.Web.Composing.Current.UmbracoHelper.Content(node.Id);
It is because you try to get something from the cache, which is not yet there.
If you want that, you have to listen to CacheRefreserBase
when you mean listen to CacheRefreserBase what do you mean? I googled that and actually got 0 results lol
It is not yet documented,
Instead if ContentService.Saving/Saved you have to listen to CacheRefresherBase<ContentCacheRefresher>.CacheUpdated and now you should be able to get the newly created node from the cache.
You can also just use save events, but then you need to get the data from the ContentService and that data will come from the database.
You can do that by doing Current.Services.ContentService. And it will be of type IContent instead of IPublishedContent.
OK that makes sense, I just tried to do this:
CacheRefresherBase<ContentCacheRefresher>.CacheUpdated += ContentService_Saved;
but its not compling
No overload for 'ContentService_Saved' matches delegate 'TypedEventHandler
So I'm guessing there is a little more to it, can I have a code sample please?
Sorry I was on my IPad. Here is an example.
It is because the arguments is different from the ones you have in your saved method:
public void Initialize()
CacheRefresherBase<ContentCacheRefresher>.CacheUpdated += CacheUpdated;
private void CacheUpdated(ContentCacheRefresher sender, CacheRefresherEventArgs e)
var payloads = e.MessageObject as ContentCacheRefresher.JsonPayload;
if (payloads == null)
The payload needs to be casted to the correct type. :-)
Did you get it to work? :-)
yes :-) Thank you!
A bit more of an explanation as to why you aren't getting results from the cache.
When you save a content node it doesn't update the cache, instead it updates the underlying database which is accessible via the content service. The Umbraco cache only contains published content, so unless the content was also published (in which case you will want to subscribe to the Published event) you'll either get nothing, or you'll get outdated content.
The published content is stored in the Umbraco Cache to make the frontend faster.
Another thing to be aware of, this isn't the best way to access the Umbraco Cache when you in an event like this. This is because it is possible that an Umbraco Context is missing, instead I'd recommend taking advantage of the built in dependency inject and having a constructor paramter on your Component of type IUmbracoContextFactory. This will have a method called "EnsureUmbracoContext" which returns a UmbracoContextReference on which you can call UmbracoContext and this has a get method to get you IPublishedContent based on an ID.
Hope that makes a bit of sense and explains why it's not working the way you are expecting.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted