• Resolved q120000

    (@q120000)


    I am trying to exclude certain pages from being cached.

    Under the “Advanced” tab, “Rejected URL Strings”, I have added:

    /contact/
    /suggest-a-website/
    /news-feeds/
    /news-feeds/other-news-feeds/

    But these pages continue to be cached.

    How can I set these pages from being cached?

Viewing 11 replies - 16 through 26 (of 26 total)
  • That’s really odd. Replace the function with this. It adds two more debug log entries.

    1. “wp_cache_is_reject: URI is empty.” if the plugin doesn’t know what the current URI (or page location) is.
    2. “wp_cache_is_reject: reject list is empty.” if the rejection list in advanced settings is somehow empty.
    function wp_cache_is_rejected( $uri ) {
    	global $cache_rejected_uri;
    
    	if ( empty( $uri ) ) {
    		wp_cache_debug( "wp_cache_is_reject: URI is empty." );
    		return true; // do not cache if we don't know the URI.
    	}
    
    	$auto_rejected = array( '/wp-admin/', 'xmlrpc.php', 'wp-app.php' );
    	foreach ( $auto_rejected as $u ) {
    		if ( strstr( $uri, $u ) ) {
    			return true; // we don't allow caching of wp-admin for security reasons
    		}
    	}
    	if ( false == is_array( $cache_rejected_uri ) ) {
    		wp_cache_debug( "wp_cache_is_reject: reject list is empty." );
    		return false;
    	}
    	wp_cache_debug( "check if $uri is rejected from this list: " . print_r( $cache_rejected_uri, true ) );
    	foreach ( $cache_rejected_uri as $expr ) {
    		if ( $expr != '' && @preg_match( "~$expr~", $uri ) ) {
    			wp_cache_debug( "URI rejected by $expr" );
    			return true;
    		}
    	}
    	wp_cache_debug( "URI was not rejected by list" );
    	return false;
    }

    Be careful when reading the debug log and make sure you’re looking at the log where a rejected page is served.

    If it says the “reject list is empty”, then make absolutely sure you have added those pages to the right place in the settings page.

    Thread Starter q120000

    (@q120000)

    Entered the code, now the debug log has “/contact/” listed 33 times. Note: I deleted the contact page from the cache and deleted the previous debug log. So the 33 entries are all new.
    “reject list is empty” is not in the log. Contact page still being cached. I am using a different browser to access the Contact page so as not to be considered a logged in user.

    I agree, this is really odd. I do not think the debug log is going to identify why the page continues to be cached. On another note, on a different website using the same theme and WPSC, with a “Contact” page, that I have set to NOT cache, and it does not cache as expected, I ran the debug script (the original script that comes with WPSC), and I get this line in the debug log: “/contact/ URI rejected. Not Caching”. So that site operates correctly and its debug log confirms it.

    OK. If you can, download your debug log, copy it to your server or to Dropbox as a .txt file and send me the URL at through the contact form at https://odd.blog/the-development-version-of-wp-super-cache/ and I’ll take a look at it.

    It has to have debug log entries for your /contact/ form.

    You could also send me your wp-content/wp-cache-config.php too. That’s the plugin configuration.

    Hopefully I’ll be able to spot what’s wrong.

    Thread Starter q120000

    (@q120000)

    Sent link to files. I checked the server error log – it was empty, no errors. Not sure if this is relevant.

    Argh, sorry about this. I started using Fastmail recently and neglected to tell my server that it wasn’t supposed to handle the email for my domains so your message got lost.

    Can you send the links to this (temporary) email instead? I’ll delete the email address after I get your message. Remove the spaces to use it.

    light.gear1706 @ fastmail.com

    Thread Starter q120000

    (@q120000)

    Not a problem. Sent to the fastmail address.

    Thanks @q120000. I got that. Did you create that debug log with the modified wp_cache_is_rejected I posted above?

    It should have shown the text “URI was not rejected by list” in the debug log at the very least, but it’s as if the “rejected” code was never run.

    Are you running a web server with a reverse proxy in front of it? I think the “cache_acceptable_files” check in “wp_cache_ob_callback” is causing the problem.

    Edit wp-cache-phase2.php again and look for “wp_cache_ob_callback”. The second line of that function is: $script = basename( $_SERVER['PHP_SELF'] );

    Add the following line immediately after it:

    wp_cache_debug( "script: $script" );

    It should look like this:

    function wp_cache_ob_callback( $buffer ) {
        global $wp_cache_pages, $wp_query, $wp_super_cache_query, $cache_acceptable_files, $wp_cache_no_cache_for_get, $wp_cache_request_uri, $do_rebuild_list, $wpsc_file_mtimes, $wpsc_save_headers, $super_cache_enabled;
        $script = basename( $_SERVER['PHP_SELF'] );
        wp_cache_debug( "script: $script" );

    Load up your contacts page again, and the debug log should have a “script:” line. On my server that says, script: index.php but maybe it’s different on your one. Is it different?

    Thread Starter q120000

    (@q120000)

    Edited file with code you emailed me. “Script” is not in the debug file.

    I’m beginning to think the WPSC plugin is corrupted. I’m running another site on the same server with the same theme and WPSC works.

    I think you might be right. It would probably be worth uninstalling it and installing it again.

    Thread Starter q120000

    (@q120000)

    Well, well… I uninstalled WPSC, removed any reference on the server of it that I could find, reinstalled and activated, set up as I had before – especially those pages I did not want cached, and it works.

    Ran debug (the stock debug) and lo and behold, I get this for the “Contact” page: /contact/ URI rejected. Not Caching

    Sorry for putting through a rabbit-hole, but I do really appreciate your help and sticking with me. Thank You.

    That’s honestly a relief that it works now. 🙂

    You (probably?) know a lot more about Super Cache than you ever wanted to!

Viewing 11 replies - 16 through 26 (of 26 total)
  • The topic ‘Exclude from cache using URL Strings’ is closed to new replies.