HOWTO: Grabbing just the Ids of pages and then populating with Examine
I would like to be able to get a list of my news article's ids from the content cache and then populate some POCOs for each of these articles using content from Examine. I can't for the life of me think how I can get these Ids without essentially grabbing IPublishedContent objects for each article. If I've already got IPublishedContent objects then there seems no point in using Examine to improve performance.
I realise there is a strong case for using examine exclusively, and not getting the Ids from the content cache, but I wondered none-the-less if someone can think of a way to achieve the solution I've described.
I did consider the extension method Pluck but as that works on a collection of IPublishedContent again I suspect it doesn't offer any performance improvements through the use of Examine.
Hi David,
Could you elaborate on why you'd go down the Examine route for populating your POCOs rather than using the IPublishedContent powered by the Umbraco cache?
Genuine question, so I can try and provide an answer.
Pagination I suppose. If I want to get a list of news items and show page 8 of 20 then you've either got to go full hog on grabbing maybe 200 news items and only showing 10 of them, but I wonder if you can just grab the ids and then populate the ones you need from examine. TBH it may be a crap idea I'm just investigating the different options rather than have to go Examine full hog which I find a pain.
Rusty from Merchello mentioned that they use this sort of approach in the back office, though I conceed that may be working wiht IContent rather than IPublishedContent which would have a stronger case for this approach.
Yep, it IContent would make sense for backoffice but not so much for the frontend of the site. As IContent contains published and unpublished information which would be useful for doing operations not available to content not available to the site. While IPublishedContent is coming from the Umbraco published cache.
Personally I would consider using UmbracoHelper's TypedContent(IEnumerable<object> ids) which will get back just those IPublishedContent for those ids. An instance of UmbracoHelper is available in RenderMvcController extended controllers and in Umbraco views.
If you're using the core ModelsBuilder you'll already have strongly typed content coming back from this, personally I prefer to use a third-party packaged Umbraco Ditto which allows you to map an IEnumerable<IPublishedContent> or single IPublishedContent to a strongly typed POCO, but this isn't required.
Umbraco's published cache is pretty quick, you'll only really have issue on first time compilation and even then with only 200 there shouldn't a problem. Subsequent calls should very very quick :)
I think the two can live side by side but so long as you're producing readable, maintainable code which doesn't cause massive issue we can be happy. :)
If you've not tried out Ditto v0.9.0 you should check out a blog article I wrote on the power of DittoProcessors, I think you might find them quite useful. They allow for so much additional functionality that ModelsBuilder doesn't necessarily do. Plus something I didn't cover you can cache individual values on a property by property basis if need be.
Not sure if my answers above helped you find the direction you're looking for, but if it did please mark it as the solution.
HOWTO: Grabbing just the Ids of pages and then populating with Examine
I would like to be able to get a list of my news article's ids from the content cache and then populate some POCOs for each of these articles using content from Examine. I can't for the life of me think how I can get these Ids without essentially grabbing IPublishedContent objects for each article. If I've already got IPublishedContent objects then there seems no point in using Examine to improve performance.
I realise there is a strong case for using examine exclusively, and not getting the Ids from the content cache, but I wondered none-the-less if someone can think of a way to achieve the solution I've described.
I did consider the extension method Pluck but as that works on a collection of IPublishedContent again I suspect it doesn't offer any performance improvements through the use of Examine.
Hi David,
Could you elaborate on why you'd go down the Examine route for populating your POCOs rather than using the IPublishedContent powered by the Umbraco cache?
Genuine question, so I can try and provide an answer.
Thanks,
Jamie
Pagination I suppose. If I want to get a list of news items and show page 8 of 20 then you've either got to go full hog on grabbing maybe 200 news items and only showing 10 of them, but I wonder if you can just grab the ids and then populate the ones you need from examine. TBH it may be a crap idea I'm just investigating the different options rather than have to go Examine full hog which I find a pain.
Rusty from Merchello mentioned that they use this sort of approach in the back office, though I conceed that may be working wiht IContent rather than IPublishedContent which would have a stronger case for this approach.
Yep, it
IContent
would make sense for backoffice but not so much for the frontend of the site. AsIContent
contains published and unpublished information which would be useful for doing operations not available to content not available to the site. WhileIPublishedContent
is coming from the Umbraco published cache.Personally I would consider using UmbracoHelper's
TypedContent(IEnumerable<object> ids)
which will get back just thoseIPublishedContent
for those ids. An instance of UmbracoHelper is available in RenderMvcController extended controllers and in Umbraco views.If you're using the core ModelsBuilder you'll already have strongly typed content coming back from this, personally I prefer to use a third-party packaged Umbraco Ditto which allows you to map an
IEnumerable<IPublishedContent>
or singleIPublishedContent
to a strongly typed POCO, but this isn't required.Umbraco's published cache is pretty quick, you'll only really have issue on first time compilation and even then with only 200 there shouldn't a problem. Subsequent calls should very very quick :)
Thanks Jamie. Yes I prefer Ditto too, but now Model Builder is in the core I don't think it's benefits justify using it.
I think the conclusion is, you can't get a list of Ids without getting the IPublishedContent. So go all examine or all content cache.
I think the two can live side by side but so long as you're producing readable, maintainable code which doesn't cause massive issue we can be happy. :)
If you've not tried out Ditto v0.9.0 you should check out a blog article I wrote on the power of DittoProcessors, I think you might find them quite useful. They allow for so much additional functionality that ModelsBuilder doesn't necessarily do. Plus something I didn't cover you can cache individual values on a property by property basis if need be.
Not sure if my answers above helped you find the direction you're looking for, but if it did please mark it as the solution.
Any other questions just let me know!
is working on a reply...