This is a particularly useful tool for cache preloading on GridPane, especially once a full site cache clear has been ran via the Self-Help tools.
This article will walk you through how to set this up for your websites and, if you wish, set it up as a cron job.
Part 1. Download Optimus Cache Prime
First, we need to connect to our server via SSH. Please see the following guides to get started:
Generate your SSH Key:
Add your SSH Key to GridPane:
Connect to your server:
We’re now going to download and unzip OCP. As I’m going to be running it as a cron job (part 4), I’m going to store it where the bulk of my other cron jobs run: /usr/local/bin. You’re welcome to install it elsewhere if you wish – it will still work correctly. To begin I’m going:
To download the file we can use the
wget command. At the time of writing, this looks as follows:
Note – we’re downloading the Linux (64-bit) version.
Part 2. Extract
The file we’ve just downloaded is a tar.gz file, so we’re going to extract the file with the
tar -xf command as follows:
tar -xf FILENAME.tar.gz
For me at the time of writing the command is therefore:
tar -xf ocp-2.7-amd64.tar.gz
Part 3. Run a preload
You may wish to test this is working correctly on a small test site. First run a full cache clear via the self-help tools like so:
Then, back inside your server, navigate to the ocp directory. I’ve installed it in /var:
And then run the following replacing the link below with your actual sitemap link:
This will now run and preload your websites cache. You can run this anytime you need to, and you can view the all of the Optimus Cache Prime commands available by entering
./ocp on it’s own while inside the ocp directory.
Part 4. Setup a cronjob (optional)
When setting up a cron job for Optimus Cache Prime, you may also wish to install the one.sh script by the same author. This is particularly useful for large sites that may take awhile to run, as we can use this to check if a preload is still in progress and abort if so – and you can use this for other cron jobs as well.
DOWNLOAD AND INSTALL ONE.SH
We can download and install using the
wget command again. I’ll be downloading and installing this inside the ocp directory as follows:
Change the permissions for One.sh
By default one.sh is installed without the permissions it needs to be able to run (execute). We need to change this with the following command:
chmod +x /usr/local/bin/ocp/one.sh
SETUP THE OPTIMUS PRIME CACHE CRON JOB
To setup our cron job, we need to run:
You’ll be given a choice of editor. We recommend nano. Hit “1” and then enter.
The crontab looks as follows:
Navigate to the bottom of the file with your down-arrow key and here we can now enter our cron job. I’ve installed OCP in /usr/local/bin/ocp (the executable “ocp” file is in the “ocp” directory), and so the cron job I’m setting up looks as follows:
*/15 * * * * /usr/local/bin/ocp/ocp https://yourwebsite.com/sitemap_index.xml
This will run OCP on your website my 15 minutes. Adjust the time as per your needs – check out https://crontab.guru/ for more information about timing your cron jobs.
SETUP THE ONE.SH CRON JOB
If you wish to also set up the one.sh script as a cron job you can add the following to your crontab instead of the cron job above:
*/15 * * * * /usr/local/bin/ocp/one.sh /usr/local/bin/ocp/ocp https://yourwebsite.com/sitemap_index.xml
SETTING A LIMIT ON HOW MANY PAGES CAN BE CRAWLED AT ONCE
To prevent potentially using a lot of server resources, you can limit how many pages OCP will preload at a given moment. Somewhere in the 5-10 range may be ideal, but you can test and adjust accordingly. For example, if you wish to set a limit of 10 pages at a time we could adjust the commands as follows:
For running without one.sh:
*/15 * * * * /usr/local/bin/ocp/ocp -c 10 https://yourwebsite.com/sitemap_index.xml
*/15 * * * * /usr/local/bin/ocp/one.sh /usr/local/bin/ocp/ocp -c 10 https://yourwebsite.com/sitemap_index.xml
SAVE YOUR NEW CRON JOB AND EXIT
Now that you’ve set your Optimus Cache Prime cron job up, save the file with CTRL+O and then Enter. Exit with CTRL+X.
You’re all set!