Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memcache - Elementor Pro #4179

Closed
Dentalicious opened this issue Apr 20, 2018 · 7 comments
Closed

Memcache - Elementor Pro #4179

Dentalicious opened this issue Apr 20, 2018 · 7 comments
Labels
compatibility/3rd-party Indicates a compatibility problem with a 3rd-party plugin or theme. status/merged Indicates when a Pull Request has been merged to a Release.

Comments

@Dentalicious
Copy link

Dentalicious commented Apr 20, 2018

Hi,

Post upgrading my hosting plan from shared hosting to 'dreampress', with the host 'DreamHost', I have been having issues for a few months now, wherein, post 'elementor pro' plugin updates (not elementor, but elementor pro), the site would look wonky as the cache was not getting cleared, to resolve this, I had to repeatedly raise tickets and seek help from the support team at Dreamhost to manually clear the cache.

This is how the site looks post updating the plugin
https://imgur.com/dvLyHSw

This is what they say about elementor pro.
1)
...The issues here are being caused by the elementor
plugin. It creates special CSS files and these files were missing from
the uploads elementor directory. You can regenerate these files at
https://www.dentalicious.com.au/wp-admin/admin.php?page=elementor-tools.
Make sure after doing this that you also purge the varnish cache by
clicking the "empty cache" link in the admin tool bar. Everything should
be loading normally now. The main problem is that this plugin does it's
own thing with separate CSS files....

However, issues were not resolved even by doing this, on digging deeper, they wrote this,

2)....
It was actually Memcached caching that was causing it to act wonky, not
Varnish. Unfortunately, there isn't a plugin that can be used to clear
Memcached. It needs to be done manually using the command line. If you
are familiar with the command line you can connect via SSH and run wp cache flush and that should take care of it.......

Just flagging issues faced by me and the issue here is that 'elementor pro' plugin updates are causing memcache caching issues and if anything that can be done from your side that would assist and make life simpler without having to go through the whole command line process cycle, then kindly have a look at it.

Thanks.

@pdclark
Copy link

pdclark commented Apr 20, 2018

Hi — Paul here at Dreamhost technical support.

As Dentalicious mentioned, we are running Memcache object cache + Varnish here on DreamPress.
The post-upgrade layout issue Dentalicious encountered with Elementor appeared to resolve when we flushed object cache. (CLI: wp cache flush)

A possible resolution for all users might be found by calling the wp_cache_flush() (function, not CLI) on the upgrader_process_complete hook, or a similar post-install / post-upgrade check & cache refresh. (The WP CLI command is slightly different than the wp_ function, but it should have an effect.)

These docs may be relevant:
https://developer.wordpress.org/reference/hooks/upgrader_process_complete/
https://codex.wordpress.org/Plugin_API/Action_Reference/upgrader_process_complete

If there's anything we can do to assist further in debug, please let us know:
The Dreamhost ticket number for this issue #8177713 — anyone on the team can look for further details for testing over LiveChat or email.

Hope that helps!

Have a great day.

Paul

@bainternet
Copy link
Contributor

@Dentalicious

We have added a new action hook elementor/css-file/clear_cache which runs when we clear the css cache so you can hook into it and clear your varnish/memcache cache as needed, Ex:

add_action( 'elementor/css-file/clear_cache', function(){
     wp_cache_flush();
});

@bainternet bainternet added the compatibility/3rd-party Indicates a compatibility problem with a 3rd-party plugin or theme. label Apr 22, 2018
@Dentalicious
Copy link
Author

Dentalicious commented Apr 23, 2018

@pdclark from Dreamhost had provided the code for ssh and it worked pretty well,

This is what is the end result, from the terminal.
….
[dp-545a030940]$ ssh user@dentalicious.com.au "cd dentalicious.com.au && wp cache flush && wp varnish purge"
user@dentalicious.com.au's password:
Success: The cache was flushed.
Success: The Varnish cache was purged.
[dp-545a030940]$

The essence of the query/request was to inquire, if I can avoid the ssh terminal process cycle, post the elementor pro plugin update, as that be great, else if that cannot be avoided, then I have the solution as mentioned above.

P.S @bainternet : Post updating the plugin to the latest release 2.0.8, the code provided, didn't work (by placing it in the child theme function file - it didn't do anything to clear the cache), however, the code provided by the DreamHost support team worked fine i.e. by using the terminal.

Thanks for your time and attention.

@bainternet
Copy link
Contributor

@Dentalicious

The CLI flash command basically calls wp_cache_flush();
https://github.com/wp-cli/cache-command/blob/master/src/Cache_Command.php#L157

as for why it didn't work from a Child theme, I have no idea.

@seanosh
Copy link

seanosh commented Aug 24, 2018

The solution presented here is incomplete and should be incorporated into elementor directly.

WordPress core itself uses wp_cache_* functions for adding/getting/deleting things like posts, postmeta, users, options, etc. An external cache store can be supported by adding a WP_CONTENT_DIR . '/object-cache.php' file with the required wp_cache_* functions. See wp-includes/load.php's wp_start_object_cache() function for details. Some examples of external object cache store include Memcache or Redis.

Using WordPress core functions like {get,update,delete}_post_meta inherently use the wp_cache_* functions which are provided by the use of an external cache store via object-cache.php.

One issue is within clear_cache function:

	public function clear_cache() {
		// Delete post meta.
		global $wpdb;

		$wpdb->delete(
			$wpdb->postmeta, [
				'meta_key' => Post_CSS::META_KEY,
			]
		);

		$wpdb->delete(
			$wpdb->options, [
				'option_name' => Global_CSS::META_KEY,
			]
		);

		delete_option( Frontend::META_KEY );

		// Delete files.
		$path = Base::get_base_uploads_dir() . Base::DEFAULT_FILES_DIR . '*';

		foreach ( glob( $path ) as $file_path ) {
			unlink( $file_path );
		}

Deleting from wp_postmeta where meta_key = '_elementor_css' (assuming defaults) doesn't then trigger the same wp_cache_delete() call(s) that WP core's delete_post_meta function does.

At this point the data in the site's DB is different from what is in the site's external object cache. Continuing on from there, all of the generated files from Elementor are then deleted. Requests arrive to the site, the meta values are pulled from that external object cache, which the logic within Elementor uses to enqueue styles for a CSS file that no longer exists.

I believe this is at the core of what @pdclark and @Dentalicious were asking about/requesting. While Elementor plugin doesn't itself make direct use of wp_cache_ functions, it does rely on or wrap WP core functions that do. By extension, Elementor should take care to invalidate that cache when it makes sense instead of requiring theme authors or site maintainers to add or execute wp_cache_flush() via WP CLI or the elementor/core/files/clear_cache hook. A lot of folks using the plugin might not be familiar with what this code is or what a hook is or where to add it.

@bainternet
Copy link
Contributor

@seanosh

Thanks for reporting, next time please open a new issue so we won't miss it.

We replaced the "direct" database calls ($wpdb->...) with the native delete_post_meta_by_key and delete_option.

should be out in next patch version.

@bainternet bainternet reopened this Aug 29, 2018
@bainternet bainternet added the status/has-pr Indicates that an Issue, or Discussion has a companion Pull Request awaiting to be merged. label Aug 29, 2018
@KingYes KingYes closed this as completed in a4e8dd2 Sep 3, 2018
@bainternet bainternet added status/merged Indicates when a Pull Request has been merged to a Release. and removed status/has-pr Indicates that an Issue, or Discussion has a companion Pull Request awaiting to be merged. labels Sep 4, 2018
@ghost
Copy link

ghost commented May 10, 2021

If you are like me and came here wondering why add_action( 'elementor/css-file/clear_cache', function(){ }); never gets called, here is the correct action name...

add_action( 'elementor/core/files/clear_cache', function(){ // Do stuff here! } );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility/3rd-party Indicates a compatibility problem with a 3rd-party plugin or theme. status/merged Indicates when a Pull Request has been merged to a Release.
Projects
None yet
Development

No branches or pull requests

4 participants