How to Clear WordPress Cache with WP-CLI

How to Clear WordPress Cache with WP-CLI

When using a cache plugin on WordPress, there is usually an option to clear the cache. However, if this option does not work or you want to try something new, you might want to try clearing your WordPress cache with WP-CLI, as we will discuss in this article.

How to Clear WordPress Cache with WP-CLI

Before starting, make sure you have installed WP-CLI on your server and that you can use its commands, for example with the command wp. If you have not installed WP-CLI yet, you can install it by following the tutorial on this page: How to Install WP-CLI on Linux.

If you have already installed WP-CLI and it is ready to use, let us go straight to the steps for clearing your WordPress cache with WP-CLI.

1. Open the WordPress Installation Folder in CLI

To use WP-CLI, you need to open your WordPress installation folder first, for example, if the installation is in the public_html folder

cd public_html

2. Clear Internal Cache

If you want to clear internal cache that does not use Object Cache like Redis or Memcached, you can use this command

wp cli cache clear

But if you want to clear the cache while keeping the most recent cache, you can use the prune option instead of clear

wp cli cache prune

3. Clear Object Cache

If you are using an object cache system like Redis or Memcached, you can use the flush command to clear the cache

wp cache flush

When the cache flush process is successful, you will receive the message Success: The cache was flushed.

That is an easy way to clear your WordPress cache with WP-CLI, allowing you to clear the cache directly without having to log in to WordPress, or perhaps even create a cron job to clear the cache automatically.

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...