Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anton 36 posts 67 karma points
    Sep 11, 2012 @ 07:54
    Anton
    0

    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?

  • Remco 4 posts 24 karma points
    Sep 20, 2012 @ 10:02
    Remco
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft