• Using Cache Enabler on the Nexcess platform and have observed this behavior 3 times in the past 12 hours on a site running The Event Calendar.

    Instead of displaying the home page layout as normal, a page of the Event Calendar archive is being displayed as the home page from the cache for non-loggedin users.

    If I login and clear the page cache for the home page, and check again it looks normal and is displaying the home page and includes comments in the source indicating it was served from the cache (<!– Cache Enabler by KeyCDN @ 29.12.2020 06:31:10 (https html) –>).

    So, I click around the site as a visitor might and view some event pages and come back to the home page and it has been replaced with a view (https://domain.com/events/page/2/ ) of the event calendar and the comments in source show it’s just been cached (<!– Cache Enabler by KeyCDN @ 29.12.2020 06:37:40 (https html) –>)

    I have the expiration set to 12 hours – so why wouldn’t it at least keep the correct view for that long? Six minutes later it’s replaced the home page cache file with the wrong content.

    Any ideas how to correct this behavior?

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Anonymous User 16850768

    (@anonymized-16850768)

    Thank you for the detailed information, @madjax. From what I’ve been able to troubleshoot so far this appears to be occurring due to how The Events Calendar plugin handles their views, which means how this plugin displays the calendar in the frontend. From the information I currently have this appears to be an issue related to how The Events Calendar plugin sets the $_SERVER['REQUEST_URI'] superglobal, which Cache Enabler relies on. Some of what I’ll detail below will be more technical, but that is just for completeness of detailing what I’ve concluded so far to reference at a later point. If the cache is empty the request looks like this:

    1. https://www.example.com/events/ is requested.
    2. Cache Enabler tries to deliver the /events/ cached page (e.g. wp-content/cache/cache-enabler/events/https-index.html). In this process we use the $_SERVER['REQUEST_URI'] variable when checking if the cache exists, then if it has expired, and then if it needs to be bypassed.
    3. The cached page doesn’t exist so Cache Enabler doesn’t deliver the cached page and instead starts capturing the page contents to cache the page. When the output buffer has ended, meaning when we are ready to take all of the captured page contents and save it as a static HTML file, we use the $_SERVER['REQUEST_URI'] variable to save the file to the server’s disk. The value we are receiving when all event views are enabled is //?post_type=tribe_events&eventDisplay=latest-past in this example. (They do update this value a couple times through their View::setup_the_loop method it looks like but that is the last value it’s updated to, at least when all event views are enabled with their updated calendar views.) In other event views we receive the same type of formatted value but with a different eventDisplay parameter value. Cache Enabler takes the page path from this value received (by parsing it and taking the PHP_URL_PATH value). In this case it’s empty, which is considered as the home page (same if it were just /). This is why various pages from The Events Calendar are being saved as the home page. The cache expiry is not considered because we are checking the $_SERVER['REQUEST_URI'] value before it’s updated by The Events Calendar plugin, which in this example is /events/.

    In summary, the above means when all event views are enabled in The Events Calendar, Cache Enabler checks /events/, believes it doesn’t exist, tries to capture the page, and is then told to save it as the home page from the value taken from the $_SERVER['REQUEST_URI'] variable that is no longer the original requested URI from the client.

    The current recommend solution to work effectively with Cache Enabler would be updating The Events Calendar settings by going to the WordPress admin dashboard > Events > Settings and disable the “Use updated calendar designs” setting. This makes this plugin work with Cache Enabler by allowing each view to be cached and delivered correctly (regardless of what event views are enabled).

    If you don’t want to disable the setting above, one workaround I’ve found so far that can be implemented to resolve this specific issue for the time being would be adding the following snippet to your website, like in your functions.php file:

    add_filter( 'cache_enabler_bypass_cache', 'cache_enabler_exclude_events_calendar' );
    
    function cache_enabler_exclude_events_calendar() {
    
    	$events_calendar_regex = '#//\?post_type=tribe_events&.+#';
    	$request_uri = $_SERVER['REQUEST_URI'];
    
    	if ( preg_match( $events_calendar_regex, $request_uri ) ) {
    		return true;
    	}
    }

    That snippet just excludes all of the calendar pages from the cache and is not the prettiest solution. (Unfortunately excluding the page paths in Cache Enabler doesn’t work due to how they update the superglobal, unless you disable one of the event views, to which you could then exclude /^\/events\/.*$/.)

    I’d love to come up with a better solution but I’m not familiar with The Events Calendar, so if you want to reach out to them and see if they have a different solution or even already know how to effectively cache their event pages with the updated calendar views that’d be great.

    Thread Starter Jackson Whelan

    (@madjax)

    @coreyk thank you for this reply, you are the man!

    Anonymous User 16850768

    (@anonymized-16850768)

    You’re most welcome! If you’re able and haven’t already, leaving an honest review is always appreciated.

    Could cache-enabler use $_SERVER['REDIRECT_URL'] instead of $_SERVER['REQUEST_URI']? That would hold the actual /events/ path instead of the weird //?post_type=tribe_events... path. And since this plugin only works with pretty permalinks that variable should always be defined and safe to use.

    Hi @madjax !

    I know it’s been awhile, but I’m hoping you see this =]

    James here with The Events Calendar.

    We’ve recently made some improvements to our plugins with regards to caching plugin compatibility, and we’re really hoping that the improvements we’ve made will have solved your issue.

    Would you mind removing the temporary solution (assuming you used it) and let us know if your website is able to function properly with our plugins and Cache Enabler both fully enabled?

    Looking forward to hearing back,

    -James

    Anonymous User 16850768

    (@anonymized-16850768)

    @madjax, @coreyw, and @highprrrr,

    We have made a change that will prevent this issue from occurring on our side as well. This will be introduced in Cache Enabler version 1.8.0. We will now only use the $_SERVER['REQUEST_URI'] as it was initially received.

    I tested the recent change made in Cache Enabler (available in our GitHub repository) with The Events Calendar version 5.3.1 as I believe that was the version used in my first reply. The issue no longer occurs when the temporary solution is removed. Yay! Furthermore, it also does not occur in The Events Calendar version 5.8.1.

    When testing the latest available Cache Enabler version (1.7.2) with latest available The Events Calendar version (5.8.1) I’m unable to replicate the issue when the temporary solution is removed. That indicates the changes you’ve made @highprrrr resolved the issued. ??

    Thread Starter Jackson Whelan

    (@madjax)

    @coreyk and @highprrrr

    Thanks for all your work on this!

    The sites we had this issue on are hosted by Nexcess and they ended up forking Cache Enabler I believe.

    We’ll see if they’ve added this change to their version and test.

    Thanks again

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Event Archive Cached as Home Page’ is closed to new replies.