Copied to clipboard

Flag this post as spam?

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


  • theevilgeek 15 posts 90 karma points
    Aug 17, 2009 @ 22:21
    theevilgeek
    0

    What is difference between UpdateDocumentCache and RefreshContentFromDatabaseAsync?

    More specifically: I've created a Document object, modified it, and now want to reliably save and publish it to the net using Umbraco 4. I was using "umbraco.library.UpdateDocumentCache()" at first, but occasionally, it would seem that the document wasn't being published (could this be a browser cache issue?).

    In some example code, I've seen "umbraco.content.Instance.RefreshContentFromDatabaseAsync();" used after publishing. Upon throwing this line after the UpdateDocumentCache() call, things seem to work reliably.

    I'd be very grateful if someone could help me to understand the distinction and use of these two methods.

     

    Thank you!

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Aug 18, 2009 @ 05:10
    Aaron Powell
    0

    For either to work you need to make sure that the document was published first, otherwise the changes wont get published out into the XML.

    The different between the two is what they involve. UpdateDocumentCache is a proper refresh of the disk cache, memory cache and sitemap. I don't believe that the RefreshContentFromDatabaseAsync does the sitemap. Also, as the name indicates, the Async method is done via the ThreadPool, so if may not be immidiately visible.

    But really I just got that from looking into the code :P

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Aug 18, 2009 @ 08:55
    Richard Soeteman
    101

    Hi,

    As @slace says you must publis the document first before calling the UpdateDocumentCache Method. I've updated the wiki on this subject last weekend.You'll find it here

    Example code from the Wiki:

    //Create new DocumentObject
    Document doc = new Document(id);
    //Mark the document for publish under Admin account
    doc
    .Publish(new User(0));
    //Publish the document by Updating umbraco.config file
    library
    .UpdateDocumentCache(doc.Id);

    Don't know about the umbraco.content.Instance.RefreshContentFromDatabaseAsync(); method but the level 2 training tells you to use the UpdateDocumentCache Method so i consider that as a best practice.

    Hope this helps you,

    Richard

  • theevilgeek 15 posts 90 karma points
    Aug 18, 2009 @ 16:18
    theevilgeek
    0

    @slace: thank you very much for that explanation. I did poke around the code but due to a certain degree of .NET newbishness, I wasn't able to wrap my mind around it. Armed with your digest, the methods now make much more sense to me. Had I more Karma, I'd definitely give you a thumbs up :)

    Richard: thank you for that concrete example. I had been running that same code and so I'm not totally sure why things stopped working for me. I suspect that I didn't actually disable my browser's cache so it's very likely this whole episode of confusion was based on some poor debugging on my part :X. In any event, thank you very much for making this process extremely clear.

     

    Thanks, all -- the Umbraco community is truly remarkable!

Please Sign in or register to post replies

Write your reply to:

Draft