Copied to clipboard

Flag this post as spam?

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


  • Dan 1285 posts 3917 karma points c-trib
    May 13, 2013 @ 16:27
    Dan
    0

    Clear cache programmatically after deleting node

    Hi,

    I have a member area on a v4.7.1 website where members can delete data from their part of a website.  The code I have is working - it deletes the chosen node from the content tree when the form is submitted by the member.  However, I don't seem to be able to clear the cache once the node has been deleted.  The node gets deleted in the content section of the CMS but it still appears in the front-end view of nodes, even after refreshing the page (rendered via an XSLT macro).  So it would appear that the XML cache isn't being regenerated correctly.  I'm calling 'Document.RePublishAll()' which I thought would work, but it doesn't.  Funnily enough though doing a 'republish entire site' from the Umbraco content section does work.

    The code I have is:

    int nodeId = Int32.Parse(nodeIdToEdit);
    var node = new Node(nodeId);
    Document pageToDelete = new Document(nodeId);
    if (umbraco.library.HasAccess(node.Id, node.Path))
    {
        User u = new User(1);
        pageToDelete.delete();
    
        //Inform the cache it should update
        umbraco.library.UpdateDocumentCache(pageToDelete.Id); // This doesn't seem to clear the cache
        Document.RePublishAll(); // This doesn't seem to clear the cache either
    }

    Can anyone suggest how to ensure that the XML cache is refreshed once the deletion is complete?

    Thanks

  • Dan 1285 posts 3917 karma points c-trib
    May 15, 2013 @ 13:41
    Dan
    100

    Ah-ha!  Just found this post http://our.umbraco.org/forum/developers/api-questions/29987-Deleting-nodes-programmatically which solves it.

    Needed to use 'umbraco.library.RefreshContent();'.  No need for Document.RePublishAll().

  • Dupeng 5 posts 25 karma points
    Sep 10, 2013 @ 16:40
    Dupeng
    0

    Thanks ,It's Works!

Please Sign in or register to post replies

Write your reply to:

Draft