Support » Plugins » If a post is updated, is the page's cache supposed to purge?

  • gL


    Hi, just a clarification on how W3 Total Cache behaves if a user goes into a published post/page and make a change.

    Is the page’s cache designed to purge simultaneously, or is one expected to wait for changes to go “live” approximately around the time interval set in Page Cache / Cache Preload / Update Interval (or manually purge cache)?

    I ask this because I see the latter behaviour in a blog I manage. Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • I was having the same issue and had my users complaining a lot about this. My solution was to build my own hook into ‘save_post’ to clear the cached page. Here is my code, which I added to my theme’s ‘functions.php’.

    ### Function: Clear W3TC Page/Post Cache Upon Edit
    $daybreak_cache_cleared = false;
    $daybreak_cache_cleared_flag = false;
    function daybreak_edit_clear_w3tc_cache( $post_id, $post ) {
        global $daybreak_cache_cleared;
        // verify if this is an auto save routine.
        // If it is our form has not been submitted, so we dont want to do anything
        if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
            return $post_id;
        if ( !$daybreak_cache_cleared_flag ) {
            $post_id = ( $parent_id = wp_is_post_revision( $post_id ) ) ? $parent_id : $post_id;
            if ( function_exists( 'w3tc_pgcache_flush_post' ) && $post->post_status == 'publish' ) {
                $daybreak_cache_cleared = w3tc_pgcache_flush_post( $post_id );
        $daybreak_cache_cleared_flag = true;
    add_action('save_post', 'daybreak_edit_clear_w3tc_cache', 10, 2);
    function daybreak_post_redirect_filter( $location, $post_id = null ) {
        global $daybreak_cache_cleared;
        if ( !$daybreak_cache_cleared ) {
            $location = add_query_arg( 'daybreak_message', 1, $location );
        } else {
            $location = add_query_arg( 'daybreak_message', 2, $location );
        return $location;
    add_filter('redirect_post_location', 'daybreak_post_redirect_filter', '99');
    function daybreak_post_admin_notices() {
        if ( !isset( $_GET['daybreak_message'] ) ) return;
        switch ( absint( $_GET['daybreak_message'] ) ) {
            case 1:
                $message = 'Problem clearing page cache or page cache doesn’t exist!';
                echo '<div id="notice" class="error fade"><p>' . $message . '</p></div>';
            case 2:
                $message = 'Cached page cleared.';
                echo '<div id="notice" class="updated fade"><p>' . $message . '</p></div>';
    add_action('admin_notices', 'daybreak_post_admin_notices');

    One thing that I also did was change my Page Cache from Disk Enhanced to Disk as there was some mention on forums that alluded to this also causing issues.

    This issue randomly occurs for some users. Please submit a bug submission form from the support tab of the plugin if the problem persists.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘If a post is updated, is the page's cache supposed to purge?’ is closed to new replies.