WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
w3tc_pgcache_flush function isn't flushing cache (6 posts)

  1. Tanin
    Member
    Posted 3 years ago #

    Manually clearing the page cache works fine, but I can't get it to work by manually calling the w3tc_pgcache_flush function. I'm calling the function from the settings page of a plugin. Any ideas?

  2. Frederick Townes
    Member
    Plugin Author

    Posted 3 years ago #

    Can you paste the code you're using?

  3. Tanin
    Member
    Posted 3 years ago #

    The function below is inside a class and is called by the class constructor. I get a valid return code but the page cache isn't empty as far as I can tell.

    function tw_flush_cache(){
    		if ($_POST['tw_flush_cache']=='1'){
    			if (function_exists('w3tc_pgcache_flush')) {
    				w3tc_pgcache_flush();
    				return 'w3';
    			} else if (function_exists('wp_cache_clear_cache')) {
    				wp_cache_clear_cache();
    				return 'sc';
    			}
    		}
    		return false;
    	}
  4. Frederick Townes
    Member
    Plugin Author

    Posted 3 years ago #

    When/where is that called? It's important to make W3TC is initialized.

  5. Tanin
    Member
    Posted 3 years ago #

    The following is a rudimentary representation of where the function lives:
    (..in the main php file of a WordPress plugin...)

    class WpPluginClass{
    	function WpPluginClass(){
    		$this->tw_flush_cache();
    	}
    	function tw_flush_cache(){
    		if ($_POST['tw_flush_cache']=='1'){
    			if (function_exists('w3tc_pgcache_flush')) {
    				w3tc_pgcache_flush();
    				return 'w3';
    			} else if (function_exists('wp_cache_clear_cache')) {
    				wp_cache_clear_cache();
    				return 'sc';
    			}
    		}
    		return false;
    	}
    }
    
    $nInst = new WpPluginClass();

    The cache should be cleared when the configuration page of the plugin is saved and thus $_POST['tw_flush_cache'] is 1. The function returns 'w3' but the cache does not seem to be cleared.

    So, how do I check W3TC's initialization status?

  6. Frederick Townes
    Member
    Plugin Author

    Posted 3 years ago #

    I take it that logic working for WP Super Cache?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic