Is UpdateDocumentCache performance and thread safety?
My hunch is that its not - But let me try to explain our design. We have a field called "Page Views" which we increment on every page visit for every page in the website. It's function is simple, increment the page view every time a page is viewed.
Now since we want to grab the "PageView" to do some automation (such as displaying a summary of popular pages) we are calling the UpdateDocumentCache on every page visit - Here's some sample code:
[RestExtensionMethod(returnXml = false)]
public static int AddPageView(int pageId)
{
Document doc = new Document(pageId);
if (doc != null)
{
int count;
int.TryParse(doc.getProperty("pageViews").Value as string, out count);
doc.getProperty("pageViews").Value = count++;
//Get the user
User user = new User(0); //default admin
//Publish the document
doc.Publish(user);
if (doc.Published)
{
umbraco.library.UpdateDocumentCache(doc.Id);
}
}
return GetPageView(pageId);
}
I'm probably wrong but this code is neither thread safe or very efficient if called on every page on the website?
Is UpdateDocumentCache performance and thread safety?
My hunch is that its not - But let me try to explain our design. We have a field called "Page Views" which we increment on every page visit for every page in the website. It's function is simple, increment the page view every time a page is viewed.
Now since we want to grab the "PageView" to do some automation (such as displaying a summary of popular pages) we are calling the UpdateDocumentCache on every page visit - Here's some sample code:
I'm probably wrong but this code is neither thread safe or very efficient if called on every page on the website?
I would keep the umbraco document purely for content and store pageviews in a seperate table outside umbraco.
Having no hands-on experience with threading vs the 'UpdateDocumentCache', so I can't really answer that part of your question.
is working on a reply...