• Resolved robertFudge

    (@robertfudge)


    Hi there,

    Is there a way to clear W3 Total Cache programmatically via a server cron job? If so can you please share with me the how-to details to achieve this?.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @robertfudge

    Thank you for your question and I am happy to help!
    Yes, it is possible to do this. The server cron job depends on your control panel.
    The best thing would be to reach out to your hosting provider to setup a custom Cron to run every 4 hours and call $w3_plugin_totalcache->flush_all();

    I hope this helps!

    Thanks!

    Thread Starter robertFudge

    (@robertfudge)

    Thanks, Do I add this function to a PHP file and point the corn job to the file?

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @robertfudge

    Thank you for your question.
    Yes, you can run the screept from corn every X hours
    For example:

    / Scheduled Action Hook
    function w3_flush_cache( ) {
    	$w3_plugin_totalcache->flush_all();
    }
    // Schedule Cron Job Event
    function w3tc_cache_flush() {
    	if ( ! wp_next_scheduled( 'w3_flush_cache' ) ) {
    		wp_schedule_event( current_time( 'timestamp' ), 'daily', 'w3_flush_cache' );
    	}
    }
    add_action( 'wp', 'w3tc_cache_flush' );

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sever cron Job: Clear cache programmatically’ is closed to new replies.