Title: Clear cache programmatically
Last modified: August 21, 2016

---

# Clear cache programmatically

 *  [B](https://wordpress.org/support/users/bh8489/)
 * (@bh8489)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/clear-cache-programmatically/)
 * I’m looking for a way to clear cache programmatically from the frontend– in other
   words, a function or action I can call, without being logged in, to flush all
   w3tc caches. This would have the same effect as the “Empty all caches” button
   on the wp admin toolbar, but be accessible in my own theme files. for example,
 *     ```
       function my_clear_all_caches() {
        	if(isset($_GET['clear_cache'])) {
        		flush_all_w3tc_cache(); // This is not a real function; I'm looking for what should be plugged in here
       	}
        }
        add_action('init', 'my_clear_all_caches');
       ```
   
 * Many thanks for any help!
 * [https://wordpress.org/plugins/w3-total-cache/](https://wordpress.org/plugins/w3-total-cache/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [ramon fincken](https://wordpress.org/support/users/ramon-fincken/)
 * (@ramon-fincken)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/clear-cache-programmatically/#post-4627743)
 * Snippit of switch case:
 *     ```
       case 'All':
       		if ( function_exists( 'w3tc_pgcache_flush' ) )
       		{
       			w3tc_pgcache_flush();
       		}
       		else
       		{
       			$notices[] = 'Error, function w3tc_pgcache_flush is not present';
       		}
       		if ( function_exists( 'w3tc_minify_flush' ) )
       		{
       			w3tc_minify_flush();
       		}
       		else
       		{
       			$notices[] = 'Error, function w3tc_minify_flush is not present';
       		}
       		if ( function_exists( 'w3tc_dbcache_flush' ) )
       		{
       			w3tc_dbcache_flush();
       		}
       		else
       		{
       			$notices[] = 'Error, function w3tc_dbcache_flush is not present';
       		}
       		if ( function_exists( 'w3tc_objectcache_flush' ) )
       		{
       			w3tc_objectcache_flush();
       		}
       		else
       		{
       			$notices[] = 'Error, function w3tc_objectcache_flush is not present';
       		}
       		break;
       ```
   
 *  [ramon fincken](https://wordpress.org/support/users/ramon-fincken/)
 * (@ramon-fincken)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/clear-cache-programmatically/#post-4627744)
 * Are you interested in a plugin that will clear your caches based on your schedule?
   I’ve build one 🙂
 *  [disagree](https://wordpress.org/support/users/disagree/)
 * (@disagree)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/clear-cache-programmatically/#post-4627747)
 * wp-cli is also great for that
 * wp w3-total-cache flush
    wp w3-total-cache pgcache_cleanup wp w3-total-cache 
   querystring wp w3-total-cache cdn_purge
 * etc

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘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/)

## Tags

 * [clear cache](https://wordpress.org/support/topic-tag/clear-cache/)

 * 3 replies
 * 3 participants
 * Last reply from: [disagree](https://wordpress.org/support/users/disagree/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/clear-cache-programmatically/#post-4627747)
 * Status: not resolved