What is WP-CLI?
One of the command-line tools designed exclusively for managing WordPress websites is WP-CLI. You may manage WordPress with only a few straightforward commands, eliminating the need to log in to your WordPress admin area and navigate through your pages.
In most cases, you can automate your processes and purge, invalidate, and warmup pages in a specific time frame. CRON jobs can be utilized to do that.
A CRON job is a job scheduler for Unix-like operating systems, to put it simply. This allows users to plan tasks (commands or shell scripts) to run on a regular basis at predetermined times, dates, or intervals.
Installing NitroPack with WP-CLI
To install NitroPack with WP-CLI, follow this set of commands:
wp plugin install nitropack
wp plugin activate nitropack
The above commands install the NitroPack plugin and then activate it.
WP-CLI and NitroPack: Supported Operations
For WP-CLI, NitroPack supports the following commands:
wp nitropack connect <api_key> <api_secret>
wp nitropack disconnect
Purge the cache for a specific URL
wp nitropack purge --purge-url=<URL>
Invalidate the cache for the entire website
wp nitropack invalidate
Run our Cache Warmup
wp nitropack warmup
Example Commands and Automation
One of the most useful commands that we can offer is for purging the cache for a specific URL.
This is great if you want to refresh the cache more frequently for specific pages only.
For example, purging a specific page:
wp nitropack purge --purge-url=https://domain.com/page
This can also be automated in a CRON job, say once every 24 hours:
0 0 * * * /path/to/wp-cli/wp --path=/path/to/your/website nitropack purge --purge-url=https://domain.com/page
You could also automate a full cache purge to be executed every 7 days:
0 0 * * 0 /path/to/wp-cli/wp --path=/path/to/your/website nitropack purge
The paths in the CRON job need to be adjusted based on where WP CLI is installed on the server and the path to your website.
Your hosting provider can help you obtain these paths, as well as set up the CRON job.