By Stephen Walker

Cache Buster

Share

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

Most Advanced WordPress Form Builder

Leave a Reply

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

RELATED ARTICLES

  • New Links Catalog

    Instead of continuing to add to the footer, I decided to create a links page that will allow me to add unlimited links, categories them, and with the use of wpGridBuilder, create a faceted filtering capability.

  • The Case of the Strange Gap

    If you are new to Avada there are some defaults that can trip you up. Page content padding is one of those, but as always, very easy to overcome.

  • Calling for Input

    I am working on my 2023 publishing schedule and want your feedback. Please submit ideas for new posts, demos, and videos.

  • To Avada, or not to Avada (Winter 2022)

    Oh no, not again. Every few months, I find new reasons to like and dislike Avada. This is just the latest installment.

  • Avada Website Showcase

    I added an Avada Showcase to allow others to share their websites. The goal is to inform and inspire others on the power of the Avada Website Builder

  • Auto Formatting Dashes and a Workaround

    In case you didn't know it, WordPress has a couple of built-in auto-formatting features that are really helpful --- the em dash and the en dash.