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
I am trying to avoid being late on a deadline. To get the IContent objects by ID from my web api method, I would use code like this:
IContent foundUmbracoContent = ApplicationContext.Current.Services.ContentService.GetById(nodeId);
However, I have been informed that this value is not cached and thus has slower performance than working with IPublishedContent objects. Unfortunately, it appears that IPublishedContent objects are not provided by any method of ApplicationContext.Current.Services.ContentService. There is a ApplicationContext.Current.Services.ContentService.GetPublishedVersion(nodeId) that I could use, but that still returns an IContent object, so I have no way to determine if it will return the cached version of the object (and I have no time for performance testing this object).
How do I obtain the IPublishedContent or equivalently cached version of the object from my Web API (GET) method?
Thanks in advance.
You need to use UmbracoContext.Current.ContentCache instead of ApplicationContext.
ContentCache returns IPublishedContent instead of the ContentService in ApplicationContext.Current.Services.
How can i get the ContentCache object using DI ?
You can create an instance of the UmbracoHelper class using the current Umbraco Context. For example:
var helper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent publishedContent = helper.TypedContent(1234);
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted