• Resolved nicoter

    (@nicoter)


    Hi,

    We have a custom plugin which dynamically creates pages with the following structure:

    www.mysite.com/custom-post-type/parameter1/parameter2/

    The pages are populated with data from text files. On the pages there’s a button to refresh the data which will result in an updated text file.

    How can we programmatically purge the URL when the text file gets updated?

    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter nicoter

    (@nicoter)

    $cacheController = new SWCFPC_Cache_Controller();
    $urls = array();
    $urls[] = 'https://www.mysite.com/custom-post-type/parameter1/parameter2/';
    $cacheController->purge_urls($urls);

    Will that work?

    Plugin Contributor iSaumya

    (@isaumya)

    Hi @nicoter,
    As far as I know, something like this is in works by @salvatorefresta. Let’s wait for him to come online and reply on this matter. I don’t think it has been released yet but I know it is in works. Let’s wait for him to confirm the timeline.

    Thread Starter nicoter

    (@nicoter)

    Hi @isaumya,
    Great to hear, looking forward of hearing details from @salvatorefresta

    Plugin Contributor Salvatore Fresta

    (@salvatorefresta)

    Hi @nicoter ,
    try this one and let me know if it works for you:

    global $sw_cloudflare_pagecache;
    
    $urls = array("first url here", "second url here");
    $error = "";
    
    if( ! $sw_cloudflare_pagecache->objects["cache_controller"]->purge_cache_urls($urls, $error) )
    	echo "Error while purging the cache: $error";
    Anonymous User 14004806

    (@anonymized-14004806)

    Hi. @salvatorefresta tried your code but that doesn’t work.
    PHP Fatal error: Uncaught Error: Cannot access private property SW_CLOUDFLARE_PAGECACHE::$objects

    Plugin Contributor Salvatore Fresta

    (@salvatorefresta)

    You’re right, try with this one:

    global $sw_cloudflare_pagecache;
    
    $objects = $sw_cloudflare_pagecache->get_objects();
    $urls    = array("first url here", "second url here");
    
    $objects["cache_controller"]->purge_urls($urls, false);

    If you want purge the whole Cloudflare cache:

    $objects["cache_controller"]->purge_all(true, false);

    Let me know

    Anonymous User 14004806

    (@anonymized-14004806)

    It worked, thank you.

    Thread Starter nicoter

    (@nicoter)

    Perfect, thank you @salvatorefresta !

    Plugin Contributor Salvatore Fresta

    (@salvatorefresta)

    You’re welcome.

    Starting from v4.3.7, you can also purge the cache using the following two commands:

    // Full cache purging
    do_action("swcfpc_purge_cache");
    
    // Partial cache purging
    do_action("swcfpc_purge_cache", array("https://example.com/some-page/", "https://example.com/other-page/"));
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Programmatically purge cache of an URL’ is closed to new replies.