You should use a persistent object cache performance
Tools > Site Health: It has recommended improvements.
A persistent object cache makes your site’s database more efficient, resulting in faster load times because WordPress can retrieve your site’s content and settings much more quickly.
Your hosting provider can tell you if a persistent object cache can be enabled on your site
Take Unbuntu as an example
Install Memcached on Ubuntu by following these steps:
Open your terminal and update your package list by running the command:
sudo apt update
Install Memcached by running the command:
sudo apt install memcached
Once Memcached is installed, you can verify its status by running the command:
sudo systemctl status memcached
If Memcached is not running, start it by running the command:
sudo systemctl start memcached
By default, Memcached listens on localhost on port 11211. To configure Memcached, you can edit the configuration file located at /etc/memcached.conf
.
To test Memcached, you can install the php-memcached
extension by running the command:
sudo apt install php-memcached
# follow your php version
sudo apt install php7.4-memcached
Once the extension is installed, create a PHP script with the following code:
<?php
$m = new Memcached();
$m->addServer('localhost', 11211);
$result = $m->get('test_key');
if ($result) {
echo $result;
} else {
echo 'No data found in cache. Adding some data now...';
$m->set('test_key', 'Hello, world!', 10);
}
This code creates a new Memcached
instance, adds a server at localhost:11211
, and attempts to retrieve a value with the key test_key
. If the value is found, it is printed. Otherwise, a message is printed and a value is added to the cache with the key test_key
.
Run the PHP script by running the command:
php script.php
If Memcached is working correctly, you should see the message “No data found in the cache. Adding some data now…” and the value “Hello, world!” should be added to the cache.
Now we can install plug-ins for WordPress
Search for Memcached Object Cache in the plug-in interface
For example, let’s take the installation of LiteSpeed Cache.
Remember to restart the apache2 service.
sudo apache2ctl restart