WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
[resolved] Home Page is Caching When It Shouldn't (2 posts)

  1. Dan Rossiter
    Member
    Posted 1 year ago #

    I have a home page which changes content based on whether the user is logged in or not.

    The primary difference in the authenticated and non-authenticated views is that the non version shows no main header (using the wp_nav_menu_items filter).

    If I am logged out, everything displays as it should. When I click the login link and authenticate a user account, I am directed to the dashboard (as expected). I then click to view the site and am shown a cached version of the homepage containing the non-authenticated view. Doing a hard refresh resolves the issue. If W3TC is disabled, all issues go away.

    It's clearly caching the queries to the DB that are generating the menu, etc, but how do I stop it? I have explicitly disabled home page caching, but that seems to only be relevant to some content. I'm not sure if it is relevant, but I am developing a child of the Responsive theme.

    The following is the W3TC documentation from the bottom of the home page after logging in (where the wrong content is loaded):

    <!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/
    
    Page Caching using disk: enhanced
    Database Caching 27/55 queries in 0.180 seconds using disk: basic
    Object Caching 1130/1248 objects using disk: basic
    
     Served from: sbirgps.org @ 2013-02-13 12:59:31 by W3 Total Cache -->

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. Dan Rossiter
    Member
    Posted 1 year ago #

    Adding the following hook seems to resolve the issue. I would still be curious as to whether there is some setting I'm missing within the plugin that would achieve the same thing.

    function wtc_kill_cache() {
        global $wp_admin_bar;
    
    	$to_mod = (array)$wp_admin_bar->get_node( 'view-site' );
    	if( $to_mod ){
    		$to_mod['href'] .= '?cache=0';
    		$wp_admin_bar->add_node($to_mod);
    	}
    
    	$to_mod = (array)$wp_admin_bar->get_node( 'site-name' );
    	if( $to_mod ){
    		$to_mod['href'] .= '?cache=0';
    		$wp_admin_bar->add_node($to_mod);
    	}
    }
    add_action( 'wp_before_admin_bar_render', 'wtc_kill_cache' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic