Cache is not working

Page caching is not working. After enabling cache in Hummingbird, pages are not cached. Debug shows:
Page not cached because of active cron or ajax request.
Loading config file.

  • Nithin
    • Support Wizard

    Hi John,

    I could notice the following in the logs for Page Cache:
    HTML corrupt. Page not cached

    This would be more related to the htaccess authentication enabled in the website side, as the website isn't publically accessible at the moment due to the authentication.

    Could you please temporarily disable the authentication, so that the website is accessible while logged out, and then check whether page cache is working fine, or not?

    Please do let us know how that goes so that we could give a closer look, if needed. Have a nice day ahead.

    Kind Regards,
    Nithin

  • John
    • Design Lord, Child of Thor

    Hi there,

    I've turned the .htaccess authentication off now and the issue still persists. The dev site is a copy of the live site which does not have .htaccess authentication.

    Here's the logs relating to turning hb caching on and loading the homepage:

    [07:15:56] Added define('WP_CACHE', true) to wp-config.php file.
    [07:15:56] Loading config file.
    [07:15:56] Do not cache admin pages.
    [07:15:57] Loading config file.
    [07:15:57] Do not cache admin pages.
    [07:15:57] Loading config file.
    [07:15:57] Skipping page. Used HEAD method. Only GET allowed.
    [07:15:57] Loading config file.
    [07:15:57] Skipping page. Used HEAD method. Only GET allowed.
    [07:16:10] Loading config file.
    [07:16:10] Request passed should_cache_request check. Ready to cache.
    [07:16:10] Caching to file: /home/user/public_html/wp-content/wphb-cache/cache/dev.mywebsite.co.uk/85b5d81f73dce3df7682b1ddf364ec8d.html
    [07:16:10] Loading config file.
    [07:16:10] Request passed should_cache_request check. Ready to cache.
    [07:16:10] Caching to file: /home/user/public_html/wp-content/wphb-cache/cache/dev.mywebsite.co.uk/85b5d81f73dce3df7682b1ddf364ec8d.html
    [07:16:10] Cached file not found. Passing to ob_start.
    [07:16:10] HTML corrupt. Page not cached.
    [07:16:10] Page not cached. Sending buffer to user.

    I'll leave the directory security off while you continue your investigations.

  • John
    • Design Lord, Child of Thor

    If I switch to the the Twenty Nineteen theme then the caching works again, so it looks like it's something related to the custom theme (written by me) that's preventing caching from working.

    The question is what? Are there any more diagnostics that you could run to work out where it is failing so that I can look to put in a fix with the theme or so that hummingbird can be modified to handle the condition?

  • Nithin
    • Support Wizard

    Hi John,

    Glad to hear you were able to find the source of the issue. I'm afraid, there isn't an easy way to pinpoint what exactly in the theme side would be causing this.

    Most probably it could happen due to custom code added in the theme side. You'll have to manually remove custom functions added part by part and then check whether the cache works during each process, to have a better idea which exact part of the code removed is causing the issue, and what further could be done to help get this fixed in the cache side.

    Was Cache working fine from the start, or the issue occurred after any recent theme edits? If the issue occurred after any recent theme edits, then it would give a better idea to temporarily revert recent changes added in the theme side and see whether it makes any difference or not.

    Please do check, and let us know how that goes, and whether you are able to find any such instances in the theme side.

    Kind Regards,
    Nithin

  • John
    • Design Lord, Child of Thor

    I did manage to correct a couple of errors in the theme (one relating to output buffer and the other a duplicate call to get_footer() on a page template). These changes did get the caching working again however it will work for a bit but then turn itself off.

    I think this may be because of a call to the following function:

    WP_Hummingbird::flush_cache();

    Is this function still working in the latest version of hummingbird or is there another way of programatically flushing the cache?

  • Nithin
    • Support Wizard

    Hi John,

    WP_Hummingbird::flush_cache();

    Is this function still working in the latest version of hummingbird or is there another way of programatically flushing the cache?

    Yes, the above-mentioned function is still present and should be working in the latest version. Could you please share the full code which you think is causing the issue, so that we could further check, and see what could be done to help get you sorted?

    Kind Regards,
    Nithin

  • John
    • Design Lord, Child of Thor

    Hi Nithin,

    This is the code:

    <?php
    if ( $_GET['clearcache'] == 'true' && is_plugin_active( 'wp-hummingbird/wp-hummingbird.php' ) ) {
      WP_Hummingbird::flush_cache();
      echo "<p>Page Cache cleared</p>";
    } else {
      echo "<p>Page Cache NOT cleared</p>";
    }
    ?>

    It is part of a page template. The purpose of the page is so that an external system that modifies data held in the wordpress database can call the page to clear the cache.

    Thanks,

    John

  • John
    • Design Lord, Child of Thor

    These are the events that occur when WP_Hummingbird::flush_cache() is run:

    [09:25:04] Removed define('WP_CACHE', true) from wp-config.php file.
    [09:25:04] Page cache deactivation: successfully purged cache folder.
    [09:25:04] Page cache deactivation: advanced-cache.php file removed.
    [09:25:04] Page cache deactivation: error removing advanced-cache.php file.
    [09:25:04] Cache directory purged

    If I run it with the arguments WP_Hummingbird::flush_cache(false,false); then caching continues to work, however the cache is then not cleared.

  • John
    • Design Lord, Child of Thor

    The cache is still disabling itself from time to time. We're not sure why this is and one issue with diagnosing the problem is that the hummingbird debug log file is deleted during the caching disable process.

    I think it would make sense for this log to be retained when caching is disabled, or at least when disabled automatically. Could that change be placed on the hummingbird development pathway?

  • Nithin
    • Support Wizard

    Hi John,

    The cache is still disabling itself from time to time. We're not sure why this is and one issue with diagnosing the problem is that the hummingbird debug log file is deleted during the caching disable process.

    Sorry to hear about the ongoing issue. I suppose the code mentioned in here is tweaked further:
    https://premium.wpmudev.org/forums/topic/cache-is-not-working#post-1409552

    Could you please share the exact code that you are currently testing, so that I could bring this into our developer's attention, and then check further about what could be done further?

    I think it would make sense for this log to be retained when caching is disabled, or at least when disabled automatically. Could that change be placed on the hummingbird development pathway?

    The logs for cache will only work if the cache is enabled when disabled there won't be any logs in general specific to the cache. Not sure whether there is any way to distinguish whether a cache gets disabled automatically as the actions are resulting from the added code tweaks. I'll make sure to bring your suggestion into our developer's attention though.

    Doesn't enabling debug mode help in this case? It should be picking up any such logs specific to Hummingbird or WP in general:
    https://wordpress.org/support/article/debugging-in-wordpress/

    Regards,
    Nithin

  • John
    • Design Lord, Child of Thor

    Hi Nithin,

    I'm now using the REST API to clear the cache, as suggested, and it's working fine:

    <?php
    			if ( $_GET['clearcache'] == 'true' && is_plugin_active( 'wp-hummingbird/wp-hummingbird.php' ) ) {
    				//WP_Hummingbird::flush_cache();
    				$url  = "https://mysite.co.uk/wp-json/hummingbird/v1/clear_cache/page_cache";
    				$query_url = $url;
    				$curl      = curl_init();
    				curl_setopt( $curl, CURLOPT_URL, $query_url );
    				curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, 0 );
    				curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 0 );
    				curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
    				curl_setopt( $curl, CURLOPT_TIMEOUT, 10 );
    				curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 10 );
    				curl_setopt( $curl, CURLOPT_HEADER, 0 );
    				curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 1 );
    				$http_code = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
    				$result    = curl_exec( $curl );
    
    				//header( 'Content-type: application/json' );
    				echo $result;
    				curl_close( $curl );
    			} else {
    				echo "<p>Page Cache NOT cleared</p>";
    			}
    
    			?>

    The problem is that there's a very intermittent issue that is causing caching to be disabled. The code above does not do that and is working fine.

    I have no idea what is causing it, but the main issue in diagnosing it is that the hummingbird debug log is deleted when the cache is disabled so I have no idea when the caching turned off and I cannot cross-check the PHP log to see if I can track down the event that might have caused it.

    I am suggesting that the hummingbird debug log is NOT deleted when caching is disabled so that the point of it getting disabled can be identified,

  • Nithin
    • Support Wizard

    Hi John,

    The code does seem to be fine, however, I'm bringing this into our developer's attention to see whether they could 'double-check if there are any further checks are needed or not.

    The problem is that there's a very intermittent issue that is causing caching to be disabled. The code above does not do that and is working fine.

    I do understand, and I'm afraid there isn't any easy way to distinguish what could be causing this. Would recommend you to test in a default WordPress theme, and see whether the same anomalies are noticed, this would give a better idea where to look at whether it's with the code added or something specific to the theme.

    I am suggesting that the hummingbird debug log is NOT deleted when caching is disabled so that the point of it getting disabled can be identified,

    I'll make sure to bring this into our developer's attention for this feature request, and see what further improvements could be done from the plugin side.

    Will keep you posted once I get further feedback asap. Have a nice day ahead.

    Regards,
    Nithin

  • John
    • Design Lord, Child of Thor

    Hi Nithin,

    Unfortunately it's not going to be practical to use a default theme as the issue is intermittent and we can't replicate it on the staging site. Currently the caching has stayed active for the past week under normal conditions so it's definitely a very rare event that it stops working.

    If there was a way of receiving a notification if and when caching is turned off automatically that would help in the interim so that I could then just go back in and re-enable it. It would also give me some clue as to what might be causing it as I would then know the time.

    Thanks,

    John

  • Nithin
    • Support Wizard

    Hi John,

    I checked with the developer and adding error_log command to the page caching disable function should help with diagnosing.

    That's by editing the file under:
    /wp-content/plugins/wp-hummingbird/core/modules/class-module-page-cache.php

    And adding the following code in the last line of the end of the following function:
    public function toggle_service( $value, $network = false ) {

    error_log( '[' . current_time( 'mysql' ) . '] - Hummingbird page caching disabled' );

    That's the final function would be like the following:

    public function toggle_service( $value, $network = false ) {
    		$options = parent::get_options();
    
    		if ( is_multisite() ) {
    			if ( $network && is_network_admin() ) {
    				// Updating for the whole network.
    				$options['enabled']    = $value;
    				$options['cache_blog'] = $value;
    			} else {
    				// Updating on subsite.
    				if ( ! $options['enabled'] ) {
    					// Page caching is turned off for the whole network, do not activate it per site.
    					$options['cache_blog'] = false;
    				} else {
    					$options['cache_blog'] = $value;
    				}
    			}
    		} else {
    			$options['enabled'] = $value;
    		}
    
    		$this->update_options( $options );
    
    		// Run activate/deactivate module actions.
    		if ( $value ) {
    			$this->activate();
    		} else {
    			$this->write_wp_config( true );
    			$this->cleanup();
    		}
    
    		error_log( '[' . current_time( 'mysql' ) . '] - Hummingbird page caching disabled' );
    
    	}

    Which should allow you to log activations. I hope this helps further with your troubleshooting.

    Kind Regards,
    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.