This article will coach you on how to clear the WordPress Object Cache using WordPress CLI. Moreover, you will also learn what Caching and Object Caching are.
What is Caching?
A cache [kash] is a temporary storage area, and Caching [kashing] is the mechanism of storing the frequently accessed data in the cache memory and reusing it and to handle subsequent requests of the same data.
Some websites might be missing an active caching system, so when users visit those websites, their requests are first sent to the target server, and then the server sends the compiled page back after processing those requests. Please note that it would not be a problem for the server if you have a low traffic site, but if you have high traffic, it may become harder for your server to complete all the requests. This is where caching comes in to comfort the server, because it saves a copy of each request, expedites the process when a new request comes, and loads from the cache memory. If there is no previously saved copy, the request goes to the server to be processed and compiled. Finally, the request is fulfilled, and the copy is safely stored.
What is Object Caching?
WordPress Object Caching is the process of saving query results of the database, so when a new request is generated, it is served from the cache memory to accelerate the completion of the request. WordPress is a Content Management System; hence, it relies extensively on a database. It means that your application database must be ultra-efficient and responsive.
What is WordPress CLI?
WP-CLI is a command-line interface for WordPress, and it is a set of command-line tools for managing WordPress installations on a server. It allows the WordPress admin users to carry out different administrative tasks without actually using a web browser. This management through the command-line interface allows the users to manage their WordPress websites by executing a set of defined commands. The scope of the tasks mainly includes upgrades, taking database backups, publishing new posts, and much more.
WP-CLI is pre-installed on all servers deployed on Cloudways.
How to Clear the WordPress Object Cache
Here are a few simple steps to clear the WordPress object cache.
First of all, you need to connect to your server remotely via SSH so you can use WP-CLI.
You can connect to your server via SSH in two ways, so choose your preferred option from the below options. You can also click on the hyperlink text of bullet points to learn about connecting remotely to the server.
In this example, we have used an SSH client named PuTTY. You will see a similar window after successful connection as shown below:
Now, you need to go to that specific directory where your webroot is located. In other words, where your wp-config.php file is located else, WP-CLI will not work. By default, it is in the public_html directory and we will also follow the default path to operate WP-CLI in this example. Enter a command mentioned below to go into the public_html folder.
Angle brackets are included to indicate the positions of your inputs so make sure to remove the angle brackets. Your application name is the same as your Database name (DB name). Click Here to find out where your application name is located.
You will see a similar window after running the above command successfully.
You may start using WP-CLI and type the command mentioned below to clear WordPress Cache once you are in the public_html directory.
wp cache flush
For WordPress multisite instances using a persistent object cache or flushing the object cache will typically flush the cache for all sites. Beware of the performance impact when flushing the object cache in production.
Source: WordPress CLI
That’s it! We hope this tutorial was helpful. If you need any help, then feel free to search your query on Cloudways Support Center or contact us via chat (Need a Hand > Send us a Message). Alternatively, you can also create a support ticket.