I have just updated to Umbraco 7.6.5 from an earlier versions Umbraco7. Retrieving nodes were a little slow do I have looked back how I do this and wondered if it was the right way. I have used this way for some time and think it may have changed.
My question is how do I know get published content from the cache as per my example. Sometimes I use the .Where alot on my example like for instance only returning nodes of a certain doc type or only returning nodes matching .GetProperty. How do I now achieve the same with 'IPublishedContent'?
The only example I could find is.....
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent content = umbracoHelper.TypedContent(123);
Simply getting published content by Id isn't enough. I need to query using properties other than just the Id.
I would say you are generally better off using IPublishedcontent as opposed to Node. Dependent on what you are trying to do, I'd also consider using Examine to query the data.
I used the following to do simple queries to the content cache...
public static List<IPublishedContent> GetPublishedContentListByDocumentTypeAlias(string documentTypeAlias)
{
var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
return umbracoHelper.TypedContentAtRoot().DescendantsOrSelf(documentTypeAlias).ToList();
}
You can also throw a bit of Linq in there querying the properties
IPublishedContent vs Node - Which one to use
Hi Guys,
I have just updated to Umbraco 7.6.5 from an earlier versions Umbraco7. Retrieving nodes were a little slow do I have looked back how I do this and wondered if it was the right way. I have used this way for some time and think it may have changed.
The way I have always for nodes is.
From what I have read 'Node' is deprecated and replaced with 'IPublishedContent' as per this link.
https://our.umbraco.org/forum/developers/api-questions/46631-Getting-Umbraco-Content-IPublishedContent-vs-IContent-vs-Node-vs-Document
My question is how do I know get published content from the cache as per my example. Sometimes I use the .Where alot on my example like for instance only returning nodes of a certain doc type or only returning nodes matching .GetProperty. How do I now achieve the same with 'IPublishedContent'?
The only example I could find is.....
Simply getting published content by Id isn't enough. I need to query using properties other than just the Id.
Thanks in advance.
Kind Regards
David
Hi,
I just found this but again I don't think its correct. In this example the code is using both 'Node' and 'IPublishedContent' to achieve what I want.
Very confusing....
http://www.jondjones.com/learn-umbraco-cms/umbraco-developers-guide/umbraco-api-explained/how-to-get-data-about-another-page-in-umbraco
Hi David,
I would say you are generally better off using IPublishedcontent as opposed to Node. Dependent on what you are trying to do, I'd also consider using Examine to query the data.
These are useful references:
1) Common pitfalls that people do when using Umbraco, it covers things like Decendent querying. https://our.umbraco.org/documentation/reference/Common-Pitfalls/
2) Performance Evaluation of Querying Umbraco - This was a really interesting article where Tim profiled accessing data in different ways that might be worth considering. http://skrift.io/articles/archive/testing-the-performance-of-querying-umbraco/
Hi,
Great reply. Thanks!
The second link was exactly what I was looking for. It was nice to see each different method speed tested.
Kind Regards
David
Pleased it helped :-)
For anyone interested....
I used the following to do simple queries to the content cache...
You can also throw a bit of Linq in there querying the properties
eg.
For anything more complex such as querying a number of properties then Examine works well. Examples of this in the links provided above.
Kind Regards
David
is working on a reply...