Title: Sever cron Job: Clear cache programmatically
Last modified: February 9, 2022

---

# Sever cron Job: Clear cache programmatically

 *  Resolved [robertFudge](https://wordpress.org/support/users/robertfudge/)
 * (@robertfudge)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/sever-cron-job-clear-cache-programmatically/)
 * 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](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/sever-cron-job-clear-cache-programmatically/#post-15347395)
 * Hello [@robertfudge](https://wordpress.org/support/users/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](https://wordpress.org/support/users/robertfudge/)
 * (@robertfudge)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/sever-cron-job-clear-cache-programmatically/#post-15347614)
 * Thanks, Do I add this function to a PHP file and point the corn job to the file?
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/sever-cron-job-clear-cache-programmatically/#post-15350492)
 * Hello [@robertfudge](https://wordpress.org/support/users/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.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * Last activity: [4 years, 3 months ago](https://wordpress.org/support/topic/sever-cron-job-clear-cache-programmatically/#post-15350492)
 * Status: resolved