Set Up Object Cache Pro
Object Cache Pro is a plugin for configuring Redis object caching on WordPress sites.
It makes your site faster and more reliable by using Redis to cache common database queries, so that your site doesn't have to hit MySQL directly every time.
Enabling on Managed WordPress and Managed WooCommerce Sites
Normally a $95/month subscription per-site, Object Cache Pro is included at no extra cost on Nexcess' Managed WordPress and Managed WooCommerce plans. It's also available to Flexible plans where WordPress is installed.
Some of our sites are using Nexcess' Managed WordPress or Managed WooCommerce plans. For these sites, Object Cache Pro is already installed, and can be enabled from the site's wp-admin. Learn more on this Nexcess article.
Enabling on Other Sites
Most of our sites will require the following steps to install and enable Object Cache Pro.
Remove Other Redis Caching Plugins
SSH into the server and navigate to the root of the site.
For good measure, it's worth ensuring that the Redis Object Cache plugin (which Object Cache Pro is forked from) is removed. If both are present, it can cause issues.
wp plugin delete redis-cache
Likewise with WP Redis:
wp plugin delete wp-redis
Install Object Cache Pro
Install the Nexcess-maintained version of the plugin:
wp plugin install https://a365f64bd6.nxcli.net/wp-content/plugins/object-cache-pro.zip --activate --force
Since we are using the --activate and --force flags, the plugin will be activated immediately after installation.
Find the Nexcess OCP License Key and Redis Configuration
The plugin will need to be licensed using Nexcess' license key.
This license key can be found in 1password > StellarWP > Web Team > Nexcess Object Cache Pro License Key.
It'll be referred to as {{ OCP LICENSE KEY }} in the following steps.
You'll also need the Redis configuration for the site. This can be found in the Nexcess Client Portal for each site.
Redis IP and port will be reffered to as {{ REDIS IP }} and {{ REDIS PORT }} respectively in the configuration.
Setup WP_REDIS_CONFIG constant in wp-config.php
Since you are already SSH'd into the server, you can edit the wp-config.php file directly.
Easiest way to do this is to use nano:
Place yourself in the root of the site and open the wp-config.php file:
nano wp-config.php
Scroll down to the bottom of the file and add the following:
define( 'WP_REDIS_CONFIG', [
'token' => '{{ OCP LICENSE KEY }}',
'host' => '{{ REDIS IP }}',
'port' => {{ REDIS PORT }},
'database' => 0, // change for each site
'timeout' => 1.0,
'read_timeout' => 1.0,
'compression' => 'zstd',
'serializer' => 'igbinary',
'async_flush' => true,
'split_alloptions' => true,
'prefetch' => true,
'debug' => false,
'save_commands' => false,
]);
Ensure that 'token' is set to the license key from 1password and host and port are set to the Redis IP and port from the Nexcess Client Portal.
Enable the Redis Cache
At this stage the plugin is installed and configured, but the Redis cache is not yet enabled. You'll need to enable the Redis cache using WP-CLI:
wp redis enable
Once you run this command, the Redis cache will be enabled and the cache will be flushed.
But you can always flush the cache manually using the following command:
wp redis flush
Verify
By this point, the plugin should be installed, configured, and enabled.
You can verify that the plugin is working by checking the wp-admin dashboard. If the plugin is active, you should see an Object Cache Pro dashboard widget.
Updating the plugin and drop-in
The Object Cache Pro plugin requires a "drop in" file named object-cache.php to be present in the content directory. This file contains a version number, which should match the version of the main plugin. When there is a mismatch between version numbers, the Object Cache Pro interface will indicate that the drop in needs to be updated.
There are multiple ways to update the drop-in, depending on the environment and site configuration.
-
Dashboard widget - If the site allows plugins to write files, the dasboard widget will display a button for updating the drop-in if it is out of date. Simply clicking the button will update things.
-
CLI - The drop-in can be updated through the command line using
wp redis enable --force. The "force" flag is needed when a version of the drop-in already exists. -
Manually - The drop-in is included in the Object Cache Pro plugin, in the "stubs" directory. This can be copy pasted into the WordPress content directory.
The drop-in plugin will need to be updated whenever there is an update to the Object Cache Pro plugin. Since we manage this through composer, we should make it a habit to run the CLI command locally whenever performing a general composer update for a site's dependencies.
We are currently including the drop-in within the site repos, to ensure it is always present. Ideally, updating the drop-in would happen locally in tandem with general maintenance updates.
wp redis enable --force
Further Reading
LiquidWeb's Internal Documentation (VPN required)
- Using Object Cache Pro on Dedicated Clustering plans running WordPress
- How to Install and License the Object Cache Pro Plugin
- Object Cache Pro - Benefits and FAQ