Update

Avada 7.8 introduced a setting in the performance options to clear the object cache. This resolves the issue described below.

The team at Theme Fusion has done a wonderful job trying to increase the performance of Avada to accommodate the variety of web hosts, unfortunately, the options can have unexpected results. When Avada 7.7 was released I started to have a problem on this website where new posts in the post cards element would not appear. Through trial and error, I found that if I modified a post cards element and changed the query parameters this was resolved. This led me to believe it was a caching problem, but no matter what I did, nothing seemed to work aside from editing the element. I reached out to the Avada support team but they could not offer a solution. This was only happening on sites hosted in Pressable. Jump to this past week and I started experiencing the same problem on another site hosted in another location but owned by Automattic (parent company of WordPress and owners of Pressable). This is a much higher tier solution and the hosting support team helped identify the problem — Avada’s query cache. It is not entirely a problem with Avada, but the Automattic locations use an advanced query caching plugin to improve performance. Because of the way Avada handles the caching (it caches the parameters), there was nothing to trigger this lower-level cache to recognize a change. From the support team:

It looks like what’s happening is that the fusion_cached_query() function is caching the WP_Query from FusionSC_PostCards by the query arguments. Unfortunately, since the query is only querying a specific category, the arguments are always the same, even if a post is removed from the category it requests the same cache key and it gets returned.

As you can see this directly impacts the post cards query loop. What to do? Fortunately, the Theme Fusion team did a good job coding and made it easy to find a solution. The support team provided a client_mu_plugin (Must Use Plugin) that uses the same code as Avada without the caching and then when the Avada function runs since the function already exists, it skips the caching function.

As you will see in the code below, removing the caching is fairly easy and Avada, seeing that the function is already enabled, will bypass the caching. Obviously, this is not something you should do unless you know your host offers a lower-level query caching function and this is proved with no support or guarantees.

<?php
/**
 * Disable Avada's Query Caching
 *
 * The built-in query caching can be overly aggressive, resulting in the frontend
 * not updating when post changes are made on the backend. Since we're using
 * Advanced Post Cache at the platform level, we don't necessarily need this extra
 * layer of caching.
 *
 * Due to the original caching using an md5 of the query args, we can't easily use
 * a post save filter to bust the cache, since we don't know which cache keys have
 * the posts we need to clear.
*/

if ( ! function_exists( 'fusion_cached_query' ) ) {

	function fusion_cached_query( $args ) {

		// Make sure cached queries are not language agnostic.
		if ( is_array( $args ) ) {
			$args['fusion_lang'] = Fusion_Multilingual::get_active_language();
		} else {
			$args .= '&fusion_lang=' . Fusion_Multilingual::get_active_language();
		}

		$query = new WP_Query( $args );
		return $query;
	}
}
function fusion_cached_query( $args ) {

		// Make sure cached queries are not language agnostic.
		if ( is_array( $args ) ) {
			$args['fusion_lang'] = Fusion_Multilingual::get_active_language();
		} else {
			$args .= '&fusion_lang=' . Fusion_Multilingual::get_active_language();
		}

		$query_id = md5( maybe_serialize( $args ) );
		$query    = wp_cache_get( $query_id, 'fusion_library' );
		if ( false === $query ) {
			$query = new WP_Query( $args );
			wp_cache_set( $query_id, $query, 'fusion_library' );
		}
		return $query;
	}

Along with this caching issue, I have that either performance settings in Avada are either redundant or create more problems in this environment.

Originally published on May 21, 2022

Change neon light signageChanges are Coming
MacBook Pro showing programming languageInstaWP - For All Your WordPress Testing

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

RELATED ARTICLES

  • Read New Avada-based website

    I am launching a new website using Avada taking advantage of the lessons learned over the past two years of builder evaluations.

    March 5, 2023

  • Read Going Green-ish

    Going Green-ish

    Do you know how much energy your website consumes per visit? I was shocked and made immediate changes.

    December 28, 2022

  • Read Analytics Alternative: Cabin.

    If you are looking for an alternative to Google Analytics, I recommend checking out Cabin - a privacy-first solution.

    December 25, 2022

  • Read New Section: Code Snippets

    I created a new Code Snippets section to start collecting and sharing code that I have found helpful for Avada or WordPress in general.

    December 18, 2022

  • Read The State of WordPress

    The future of WordPress is very bright, but it is going to take a new way of thinking and a willingness to learn new things. Gutenberg is only a part of that future.

    December 15, 2022

  • Read Styling the RankMath Sitemap

    Styling the RankMath Sitemap

    If you are a RankMath user, you may know that they recently introduced a feature that automatically generates an HTML version of the XML sitemap. This post is to share the CSS I am using to add some layout to an otherwise long list of links.

    December 11, 2022